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
- product three
- product two
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>
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: