Show the subcategories of current category.
Wordpress Snippets
- Show the subcategories of current category.
- Show post titles alphabetically
- Return child cat’s to parent cat’s template
This snippet copied and pasted into the regular “Category.php” template will produce a list of subcategories for the current category, if they exist. Nothing will show if there are no subcategories. Change the “Narrow Your Search:” text to your own title.
This bit goes into the Category template, after the loop, in the place where you want the subcategories to show:
<?php if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
echo "<h2>Narrow Your Search:</h2>";
wp_list_categories('orderby=name&show_count=0&title_li=
&child_of='.$this_category->cat_ID);
}
} ?>
All the credit for this cool bit of code goes to Joost De Valk.
Filed under: Heart & Soul Health
1 Comment
Link directly to this entry
























