WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Supposed the specified category name is "product", which has three layered sub-categories. The structure is like the following:

  • product one
    • product two
      • product three
        • product four

I want to output all the subcategory names in the sidebar.php of my theme. How do I do?

in my theme index.php i using: <?php include("productHallofHome.php");?> in productHallofHome.php i using code:

<ul class="productList_h">
<?php wp_list_categories( 'child_of=4&depth=0'); ?>
share|improve this question
up vote 0 down vote accepted

Please have a look at wp_list_categories, which is all you need. Just choose the arguments to your liking and place the code in your sidebar.

Suppose, the ID of your 'product' category is 666, then the basic code could look like the following:

<?php wp_list_categories( 'child_of=666&hide_empty=0'); ?>
share|improve this answer
i am sorry, it not work.it shows no category. – down1337 Mar 11 '13 at 7:08
Please edit the question and add the current code to it so we can see what you tried (and maybe why/where you failed). – tfrommen Mar 11 '13 at 7:14
it's ok now. but it only output the first layer category name. eg:the above is output product two. can't ouput product three product fou – down1337 Mar 11 '13 at 13:15
If you didn't include the argument depth=1 it should be 0 by default (which means all the way down). Please edit the question and include your current code. – tfrommen Mar 11 '13 at 13:18
i put my code to my question, thank you. when i add depth=0, it is only output the first layer category name – down1337 Mar 11 '13 at 13:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.