List subcategories when in a category, and brothers if in subcategory
-
I’ll try to be the more descriptive as I can.
I’m trying to list in a category page its children and, when in a subcategory page, to list its brothers.
I have to say that I’m using the news theme and editing the loop-meta.php but I think it’s not so important.
I read this topic that is quite similar.
In particular I used the code from anvesh:<?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&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 } ?>
That works, but there is a Problem: when in a subcategory page, get listed not only the brothers but also the current subcategory.
I.e.:
I’m in SUB 1
the list is:
– SUB 1
– SUB 2
– SUB 3
etc. I would like to exclude the current subcategory from the brothers. For the rest, it’s perfect (the best would be display the parent but…)
- The topic ‘List subcategories when in a category, and brothers if in subcategory’ is closed to new replies.