私には 7 つのカテゴリ (親) があり、各カテゴリには 15 のサブカテゴリがあります。
あるカテゴリ (親) を選択すると、その特定の親カテゴリ (親) のサブカテゴリ (子) のみを表示したい。
サブカテゴリ (子) をクリックすると、その投稿のみが表示されます。
と がfron_page.phpありcategory.phpます。
これを最初にサブカテゴリを個別に表示し、次にそのサブカテゴリを新しいファイルに個別に投稿して、ユーザーが表示したいようにするにはどうすればよいですか。
このコードは次のことに役立ちます。
<ul>
<?php
$cats = get_the_category();
$mycat = $cats->cat_ID;
wp_list_categories('orderby=id&child_of='.$mycat);
?>
</ul>
また
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<ul>'.$this_category.'</ul>';
}
}
?>
私に教えてください。
幸運を!:)
1) サブカテゴリのみを表示:
<?php
// if the page visitor views is a category page
if (is_category())
{
$cur_cat = get_query_var('cat');
if ($cur_cat)
{
$new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat . '&depth=1&title_li=&&show_count=1&hide_empty=0');
echo '<ul>' . $new_cats . '</ul>';
}
}
?>
2) 上位カテゴリをすべて表示:
<?php
wp_list_categories('depth=1&title_li=&exclude=1&show_count=1&hide_empty=0');
?>
3) すべてのトップ カテゴリとサブカテゴリをツリー メニューのように表示する:
Use plugin, called FoCal
4) このトピックを表示
http://wpworks.wordpress.com/2011/01/13/displaying-categories-and-subcategories-tree-on-wordpress/