So basically this hack is allowing you to List subcategories if viewing a Category, and brothers / sibling categories if in subcategory.
<?php if (is_category()) { $this_category = get_category($cat); } ?> <?php if($this_category->category_parent) $this_category = wp_list_categories('orderby=id&show_count=0 &title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent. "&echo=0"); else $this_category = wp_list_categories('orderby=id&depth=1&show_count=0 &title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID. "&echo=0"); if ($this_category) { ?> <ul> <?php echo $this_category; ?> </ul> <?php } ?>
Paste the above code wherever you like the categories to display and modify it however you please. The code listed above, when you visit the subcategory from the main category, hides the main category and only shows the subcategories.
If you want to show the main category also on subcategory pages, just remove the parameter depth=”1″ from the code above.
Don’t forget that you’ve seen this first at SEO expert Paul Hoda’s Blog.