Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'); ?>
    </ul>
share|improve this question
add comment

1 Answer

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:

<ul>
<?php wp_list_categories( 'child_of=666&hide_empty=0'); ?>
</ul>
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). –  t f 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. –  t f 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
show 6 more comments

Your Answer

 
discard

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.