Show only subcategories of wordpress

I have 7 categories (parents), and each category has 15 subcategories.

When I select a category (parent), I want to display only subcategories (children) of that particular parent category (parent).

After I click on a subcategory (child), it should display only its messages.

I have fron_page.php and category.php .

How can I write this to show the subcategories separately first, and then publish this subcategory separately in the new file that the user wants to see.

+1
source share
2 answers

This code should help you:

 <ul> <?php $cats = get_the_category(); $mycat = $cats->cat_ID; wp_list_categories('orderby=id&child_of='.$mycat); ?> </ul> 

OR

 <?php if (is_category()) { $cat = get_query_var('cat'); $this_category = get_category($cat); $this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0"); if($this_category !='<li>No categories</li>') { echo '<ul>'.$this_category.'</ul>'; } } ?> 

Let me know please.

Good luck! :)

+3
source

1) Display only subcategories:

 <?php // if the page visitor views is a category page if (is_category()) { $cur_cat = get_query_var('cat'); if ($cur_cat) { $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat . '&depth=1&title_li=&&show_count=1&hide_empty=0'); echo '<ul>' . $new_cats . '</ul>'; } } ?> 

2) Showing all the best categories:

 <?php wp_list_categories('depth=1&title_li=&exclude=1&show_count=1&hide_empty=0'); ?> 

3) Display all top categories + Subcategories, such as tree menus:

 Use plugin, called FoCal 

4) view this topic

 http://wpworks.wordpress.com/2011/01/13/displaying-categories-and-subcategories-tree-on-wordpress/ 
0
source

All Articles