• Hi guys,

    Im having a bit of trouble working out how to list sub categories of parent id, and to also show the parent in the list. For example, my site structure is something similar to…

    Brands > Nike > Nike Golf > Nike Golf Clubs > Product/Post

    Im trying to create a sidebar for the ‘Nike Golf Clubs’ category page so that it lists sub categories of the parent id, and includes the parent eg. Nike Golf. Like so..

    Nike Golf
    -Nike Golf Clubs
    Nike Football
    Nike Basketball

    The code im currently using works fine but it does not show the parent which i would like to improve the sites navigation.

    <?php
    if (is_category()) {
    $this_category = get_category($cat);
    }
    ?>

    <?php
    if($this_category->category_parent)
    $this_category = wp_list_categories(‘show_count=0&title_li=&child_of=’.$this_category->category_parent.”&echo=0″);

    if ($this_category) { ?>

      <?php echo $this_category; ?>

    <?php } ?>

    If anyone could offer any help in fixing this i would be very grateful. Thanks.

Viewing 1 replies (of 1 total)
  • current_category
    (integer) Allows you to force the “current-cat” to appear on uses of wp_list_categories that are not on category archive pages. Normally, the current-cat is set only on category archive pages. If you have another use for it, or want to force it to highlight a different category, this overrides what the function thinks the “current” category is. This parameter added at Version 2.6

    Un-tested but an optimized version of your code, something like this.

    <?php
    if (is_category() && $cat->category_parent) {
    	wp_list_categories( 'title_li=&current_category='.$cat->ID.'&child_of='.$cat->ID );
    }
    ?>

    Source Codex – wp_list_categories

    HTH

    David

Viewing 1 replies (of 1 total)
  • The topic ‘How can i include the parent when listing sub categories?’ is closed to new replies.