Forums

List all categories in current category family? (3 posts)

  1. barnz2k
    Member
    Posted 1 year ago #

    I want to have a category widget which shows all categories in the same family as the current category, or lists the top categories only if no category is selected.

    eg; If I have these categories:

    Cat1
    - cat1.1
    - cat1.1.1
    - cat1.2
    -cat1.2.1
    - cat1.3
    Cat2
    - cat2.1
    - cat2.2
    Cat3
    - cat3.3

    And if I am in category "cat1.2" I want it to list all categories from Cat1 down and nothing else, or only the top of Cat2 and Cat3.

    I have searched but can't find anything to do this
    Thanks!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

  3. barnz2k
    Member
    Posted 1 year ago #

    little more help please?

    What I've come up with so far is

    if ( is_category() ) {
      $current_cat = $cat->category_parent;
    
      wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat);
    }

    This seems to show all categories, while below only shows the sub categories

    if ( is_category() ) {
      $current_cat = get_query_var('cat');
      wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat);
    }

    I need it to go just one or two parents higher, and list all below.

Topic Closed

This topic has been closed to new replies.

About this Topic