List subcategories if viewing a Category, and brothers if in subcat.
-
I’ve been searching for hours without finding an answer (even though i think i’ve seen this before).
I have a category based site, nothing too complicated since it just uses two levels, Parent categories and children categories.All I need to do is to display a list of subctegories specific to a parent category in the sidebar when viewing it. So when Im viewing the “Parent” category i get a list of “Children” in the sidebar. That’s easy right? :
<?
if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != “”) {
echo “”;
echo ”- “;
wp_list_categories(‘hide_empty=0&title_li=&child_of=’.$this_category->cat_ID);
echo ““;
}
}
?> `But the problem i hav is that when I enter a subcategory, sinci it doesn’t have children, the list disappears.
How can I make it show a list of children categories if viewing a parent, and a list of brothers if viewing a children?
Is there a plugin/widget that already does this?
This is very similar to the “Show subpages even if on a subpage” thing in the codex, only with categories.
Please help me or point me in the right direction, I know lots of people have the same question.
Thanks!
`
- The topic ‘List subcategories if viewing a Category, and brothers if in subcat.’ is closed to new replies.