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>';
?>
精彩评论