WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to show parent's subcategories in a category page

How to show parent's subcategories in a category page

  • JohnPixle

    @john_pixle

    Hello. I am completely new to php and I am having a very hard time to make things happen… I would appreciate any help.

    What I want to do:
    I have a structure like this:

    Parent Category A
    -Child Category 1
    -Child Category 2
    -Child Category 3

    Parent Category B
    -Child Category 1
    -Child Category 2
    -Child Category 3

    At first I wanted when the user is in Parent Category, To display the subcategories of this category along with all the posts that are contained in these categories. I have made it using the following code, and works fine:

    if (is_category()) {
      $this_category = get_category($cat);
      if (get_category_children($this_category->cat_ID) != "") {
        echo "<div id=catlist>";
        wp_list_categories('orderby=id&show_count=1&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);
        echo "</div>";
      }
    }

    you can see the result here: (sorry, it’s in greek)
    http://www.humanspace.gr/category/well-being/

    You can see it at the top of all posts.

    Now, what I want to do is to keep this same category listing at the top area when the user goes to one of these child categories…

    I have tried :

    if (is_category(fengshui)) {
      $this_category = get_category($cat);
      if (get_category_children($this_category->cat_ID) != "8") {
        echo "<div id=catlist>";
        wp_list_categories('orderby=id&show_count=1&title_li=&use_desc_for_title=1&child_of=8'.$this_category->cat_ID);
        echo "</div>";
      }
    }

    but doesn’t seem to work… the id 8 is the category id of the parent category from which I want to display the children…

    i am sure I’ve messed up with the code somewhere…
    Thank you for your support.
    John

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to show parent's subcategories in a category page’ is closed to new replies.
Skip to toolbar