开发者

Show subcategory of a particular Wordpress category

I want to show the hierarchical list of categories using wp_list_categories but I want to show only one category and its subcategory

<ul>
   <li ><a href="#">Main category</a>
    <ul >
     <li ><a href="#">Sub cat 1</a></li>
     <li ><a href="#">Sub cat 2</a></li>
        <li ><a href="#"开发者_开发技巧>Sub cat 3</a></li>
    </ul>
   </li>
</ul>

I tried this code but it didn't work out

<?php wp_list_categories('include=19&depth=2&style=list&hierarchical=1&title_li=0&hide_empty=0'); ?>

Can anybody suggest a solution?


You can try something like this:

<?php
$subcategories = get_categories('&child_of=4&hide_empty'); // List subcategories of category '4' (even the ones with no posts in them)
echo '<ul>';
foreach ($subcategories as $subcategory) {
  echo sprintf('<li><a href="%s">%s</a></li>', get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));
}
echo '</ul>';
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜