List Current Category and its Sub-Categories….
-
I am trying to list the category and all sub categories of the current category or sub category page. So it I am on category 1, a list will show with category 1 and all sub-cats. If I am on a sub category of category 1, a list will again show with category 1 and all sub-cats….so the same list shows relevant to the current category, regardless of whether the current category is a parent or child.
The following code works but it 1) requires me to add an entry for every single category 2) only lists sub-categories…. for each page, I am unable to list the sub cats and the cat simultaneously, if I add include:26, it will only list parent and if I add child_of=26, it will list children but not parent… any feedback appreciated!:
<?php if (is_category(26)){ ?> <ul><?php wp_list_categories('child_of=26&hierarchical=0&title_li=0&hide_empty=0&depth=1'); ?></ul> <?php }elseif(is_category(22)){ ?> <ul><?php wp_list_categories('child_of=22&hierarchical=0&title_li=0&hide_empty=0&depth=1'); ?></ul> <?php }elseif(is_category(21)){ ?> <ul><?php wp_list_categories('child_of=21&hierarchical=0&title_li=0&hide_empty=0&depth=1'); ?></ul> <?php }else{ ?> <ul><?php wp_list_categories('orderby=ID&hierarchical=1&exclude=1&title_li=0&hide_empty=0&depth=1'); ?></ul> <?php } ?>
- The topic ‘List Current Category and its Sub-Categories….’ is closed to new replies.