Display the list of subcategories of a category in WordPress







Some time we need display subcategories of a parent category in wordpress. Here is simple code snippet to do that.
Use this code in your template file where you want to display the subcategories list.

<?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>';
?>

Share With Friends

Also Read   Display latest post in wordpress with Time ago format

Speak Your Mind

*

Time limit is exhausted. Please reload CAPTCHA.