• 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!

    `

Viewing 2 replies - 16 through 17 (of 17 total)
  • Hello all,

    I followed the code shown in the last post of anvesh. I was just wondering how to solve the following:
    If i am on a parent category with no children it displays: “No categories“. Can i remove that line somehow?

    I’ve been truying to follow MAD000’s code as well, but here i’m having troubles showing the childcategories if i’m already on that specific childcategorie. if anyone knows how to resolve this, it would also help me out ??

    Can anybody point me to the right direction? Please bear in mind that i’m not quite skillfull in php ;o)

    I am needing to change the text “No Categories” as well. The only post I was able to find stated this:

    <?php
    $cats = wp_list_categories(‘echo=0’);
    if ( !preg_match( ‘/No\scategories/i’, $cats ) ) { echo $cats; }
    ?>

    It seems to cause issues with the above code. If anyone could help that would be great. If there are no categories left I would like to have it same something different or be removed all together.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘List subcategories if viewing a Category, and brothers if in subcat.’ is closed to new replies.