Provide zblog template_zblog them_wordpress template download and customization

Wordpress calls all subcategories of the current classification

Tianxing Studio 2019-12-25 20:32 Wordpress Tutorial three thousand three hundred and eighty-two 0 Comments


wordpress When creating enterprise themes, it is common to call all subcategories under the current category. To implement this, follow the steps below.

First, write a function in "functions. php" of the topic. The code is as follows:

 //Get subcategories function get_category_root_id($cat){     $this_category = get_category($cat);     while($this_category->category_parent) {         $this_category = get_category($this_category->category_parent);     }     return $this_category->term_id; }

Then write the following code on the page to be called:

 <? php if(is_category()) {     $cat = get_query_var('cat');     $categoryurl = get_category_link($cat);     if(get_category_children(get_category_root_id(the_category_ID(false)))!=  "" ) {         echo wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)).  "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC");     } } ?>

Finally, adjust the css by yourself.


Can't find a tutorial that can solve your problem?

You can try to search or ask questions directly online. We also provide charging technical support. If you need it, you can contact us online.

Online questions Online Service

welcome you Comment: Cancel Reply

 Please fill in the verification code
  • Latest articles
  • Hot article ranking
  • Most Comments
Label aggregation
  • Sign in
  • Registered account Forgot your password?
  • register
  • Already have an account? Direct login Forgot your password?
  • Social account login