1

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>

1 Answer 1

0

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>
11
  • i am sorry, it not work.it shows no category.
    – down1337
    Commented Mar 11, 2013 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
    Commented Mar 11, 2013 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
    Commented Mar 11, 2013 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
    Commented Mar 11, 2013 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
    Commented Mar 11, 2013 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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