WordPress.org

Ready to get started?Download WordPress

Forums

How to show parent's subcategories in a category page (3 posts)

  1. john_pixle
    Member
    Posted 3 years ago #

    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

  2. Tara
    Member
    Posted 3 years ago #

  3. john_pixle
    Member
    Posted 3 years ago #

    thanks man, really helped a lot...

Topic Closed

This topic has been closed to new replies.

About this Topic