私はワードプレス開発の新人です。私はワードプレスの特定のページに特定のカテゴリを表示する方法を知りたい。私は私のプロジェクトでそれを行う必要があります。Wordpressの特定のページに特定のカテゴリのみを表示するには?
0
A
答えて
0
は、リンクとしてカテゴリのリストを表示します。
基本的には、この機能をwp_list_categories();
と呼んで、カテゴリを表示する場所に表示する必要があります。
このオプションは、表示するカテゴリIDのリストを受け入れるinclude
を使用します。この
$args = array(
'hide_empty' => 0, //Show me all the categories, even the empty ones
'orderby' => 'count', //which accepts a string. You can pick from the following options: ID to order the categories by their ID (no, really?), name to sort them alphabetically (the default value), slug to sort them in the alphabetical order of their slugs, and count to order by the number of posts they contain.
'order' => 'DESC', //The chosen order can be reversed by setting DESC (descending) as a value for the order option (by default this option is set to ASC (ascending)).
'include' => '15,16,9'
);
wp_list_categories($args);
同様
$categories = get_categories(array(
'orderby' => 'name',
'order' => 'ASC',
'include' => '15,16,9'
));
foreach($categories as $category) {
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url(get_category_link($category->term_id)),
esc_attr(sprintf(__('View all posts in %s', 'textdomain'), $category->name)),
esc_html($category->name)
);
echo '<p>' . sprintf(esc_html__('Category: %s', 'textdomain'), $category_link) . '</p> ';
echo '<p>' . sprintf(esc_html__('Description: %s', 'textdomain'), $category->description) . '</p>';
echo '<p>' . sprintf(esc_html__('Post Count: %s', 'textdomain'), $category->count) . '</p>';
}
差wp_list_categories
とget_categories
間プレスの機能get_categories()
とwp_list_categories()
get_categories();
機能を使用してカテゴリを表示する別の方法は、ほぼTであります彼は同じです。彼らはほとんど同じパラメータを使用していますが、それらの間に違いがあります:
get_categories()
関数は、クエリパラメータに一致するカテゴリオブジェクトの配列を返します。 wp_list_categories()
には、カテゴリのリストがリンクとして表示されます。 WordPressの開発者のdocumention:
get_categories():http://codex.wordpress.org/Function_Reference/get_categories
wp_list_categories():スタックオーバーフローにがhttp://codex.wordpress.org/Function_Reference/wp_list_categories
関連する問題
- 1. Wordpress:特定のカテゴリのタグを表示するには?
- 2. シルバーストライプ、特定のカテゴリのみを表示
- 3. 特定のカテゴリ内の投稿ページにWordpressウィジェットを表示する
- 4. Wordpress:特定のページにのみメニューを表示
- 5. Wordpressカテゴリのリダイレクトと特定のカテゴリ別投稿を表示
- 6. 特定のカテゴリのWooCommerce製品ページにカスタムボタンを表示する
- 7. Wordpress:特定のカテゴリの単一の表示を防止する
- 8. パーマリンクに特定のカテゴリのみを表示WordPressのカスタム投稿タイプ
- 9. Algolia - WordPress、1つのCPT内の特定のカテゴリのみを表示する(インデックス)
- 10. 特定のカテゴリーの投稿ページにWordpressウィジェットを表示する
- 11. Wordpressで特定の投稿カテゴリを表示する
- 12. Woocommerce - 特定のカテゴリのクリックで別のページを表示する
- 13. Wordpressで特定のカテゴリの表紙画像を設定する
- 14. ページに特定のカテゴリの記事がある場合 - wordpress
- 15. 特定のカテゴリにのみ項目を表示
- 16. 投稿の特定のカテゴリのみを表示する
- 17. Wordpress:2つの特定のカテゴリにある場合は投稿を表示
- 18. 特定のページIDの子ページのみをACFリレーションシップセレクトボックスに表示
- 19. Wordpressで特定のカテゴリのランダムなページを表示するにはどうすればよいですか?
- 20. Wordpress:特定のカテゴリのシングル投稿のみにカスタムメタデータを表示する方法はありますか?
- 21. WordPressの特定のカテゴリの投稿URL
- 22. 特定のページのWordpressカスタムメタボクス
- 23. ワードプレスで特定のカテゴリのタイトルを非表示にする
- 24. ワードプレスのポストループに特定のカテゴリを表示する
- 25. Wordpress:[新規追加]ページのユーザー役割から特定のカテゴリを非表示にする
- 26. フィードを特定のカテゴリのみに限定する
- 27. 特定のWordpressカテゴリからポスト投稿
- 28. 特定のWordPressページをHTTPSにリダイレクト
- 29. 特定のカテゴリのサムネイルに画像オーバーレイを追加する - wordpress
- 30. Drupal6 - ページ内の特定のユーザーからの特定の表示を表示
ようこそ。一般的なヘルプや推奨事項について質問することはお勧めできません。[許可されるトピック](https://stackoverflow.com/help/on-topic)を参照してください。これはコード作成サービスではなく、あなたが問題を調査し、投稿する前に解決しようとしていることが予想されます。 [Stack Overflowユーザーにどの程度の研究努力が期待されていますか?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users)と[どのように私は良い質問をする](https://stackoverflow.com/help/how-to-ask) – FluffyKitten