How to: Show or display only child categories

Wordpress theme development is fun. But, it also can be a headache when we don’t have the right code snippets to use. Despite the huge availability of Wordpress snippets around it is somewhat difficult to find exactly what we needed. Here in this article you will find out how to display only child categories or how to hide subcategories.

By default, Wordpress lists all the categories that has at least 1 post attached. If you want to know how to hide your sub-categories in WordPress, simply copy paste following code into your stylesheet.

.children {display:none;}

You can also style the child categories according to this way.

To display only children categories helps a lot for those who want to show more than one navigation in their theme. It would help you a lot if you are going to develop a magazine based theme. You can display different categories on different places on your theme as well by using “show only children” snippet.

To do so, open your theme file (most probably sidebar.php) and copy paste following code into your theme file.

<?php wp_list_categories('use_desc_for_title=0&child_of=8'); ?>

Dont forget to replace ID of your category with 8

Leave a Reply

ADVERTISEMENT

Log in - BlogNews Theme by Gabfire themes