When creating a wordpress topic, you often encounter the problem of displaying subcategories under the current category on the wordpress category page. 1. Now add the following code functionget_category_root_id ($ cat) {$ this_categoryget_category ($ cat) to function. php)
When creating a wordpress topic, you often encounter the problem of displaying subcategories under the current category on the wordpress category page.
1. add the following code to function. php.
Function get_category_root_id ($ cat) {$ this_category = get_category ($ cat); // Obtain the current category while ($ this_category-> category_parent) // if the current category has a parent category, loop {$ this_category = get_category ($ this_category-> category_parent); // set the current category to the upper-level category (climbing)} return $ this_category-> term_id; // return the ID of the root category}
2. paste the following code in the area where the secondary category is to be displayed on the page:
'; 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"); echo ''; } }?>
This function displays the subcategories of the current category (secondary category) on the category page and article page ).