
Download
[ Download ]

The code that I will explain here will display sub categories only when you are viewing a single category which contains sub categories. This template hack is very simple.
Place this code in your category.php file
<?php if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category->cat_ID) != "") { echo '<h2>'; single_cat_title(); echo '</h2>'; echo '<ul>'; wp_list_categories('orderby=id&hide_empty=1&show_count=0&title_li=&child_of='.$this_category->cat_ID); echo '</ul>'; } } ?>
Put this snippet in your category.php template file and It should show sub categories for your parent categories on category pages.
This code simply does the following:
Customize the wp_list_categories() function
wp_list_categories('orderby=id&hide_empty=1&show_count=0&title_li=&child_of='.$this_category->cat_ID);
By default it displays categories by ID, hides empty categories, and does not show number of posts within each category.
The following code will show post count besides each category
wp_list_categories('orderby=id&hide_empty=1&show_count=1&title_li=&child_of='.$this_category->cat_ID);
Very easy! You can also change hide_empty=1 to hide_empty=0 to display
empty categories (even if they do not have posts, they appear!)
Source from [ http://mywordpressdesign.com/ ]