You are currently viewing How to Show All Child Categories from Parent Category in WordPress

How to Show All Child Categories from Parent Category in WordPress

Sometime when using WordPress custom menu, you do not want to add the child category from parent category into the created menus. However you want the child category to show when you are browsing parent category, this is useful if you have a wide variety of sub-category for a certain category. Take for example from above image,

Art And Design (Top Level Parent Category)
– Print Design (Secondary Child Category)
   – Technology (Grand Child Category)
– Web Design (Secondary Child Category)

Usually, you will be adding top level parent category into your custom menu but all the others child and grandchild category will be hidden from the site so users will not be able to browse them.

In this tutorial, its easy to show all the sub categories from the current parent category you are viewing. Just add this snippet code into anywhere you want in template, preferably in sidebar or some where near the navigation menus.

if ( is_category() ) {
$this_category = get_category($cat);
$this_category = wp_list_categories(‘orderby=id&depth=5&show_count=0&title_li=&use_desc_for_title=1&child_of=’.$this_category->cat_ID."&echo=0");
echo ‘<ul>’. $this_category . ‘</ul>’;

Final Result

Now when i’m currently browse the ‘Art and Design’ category, the sub category for this category will automatically show in bottom of the navigation where i’ve place the snippet code above.

You can change the depth=5 to how many sub level you want to show within the parent category.

Richie KS

The creator and author of He also a WordPress, BuddyPress, BBPress and Ecommerce Theme Developer.

This Post Has 12 Comments

  1. iwan sugiharto

    I try to put this on side bar (i replace on sinle page) doesnt work. Help pls

  2. Chris Sadler

    I was able to get this to work, thanks! I was wondering if there is a way to have a link back to the parent category from the child as well?

  3. Katya

    I don’t know Where Do I Put This Code?

  4. lirikpedia

    Thank you very much. You save my time. I used your snippet code on my site.

  5. Matthew Barrowclough

    First off, excellent theme and thank you so much for the ongoing support.

    I have implemented the script above which is working for me. Is there an additional script or is it a CSS change so that I can see the child categories upon hover while on the homepage?

Leave a Reply