在WordPress获取父分类是比较常见的,本站今天给大家讲讲怎么获取父分类的所有子分类。
其实也很简单,主要用到这个函数:wp_list_categories(),不过在用函数之前需要添加一段代码:
//父分类获取所有子分类
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; // 返回根分类的id号
}
把上面代码添加到主题的 function.php 文件最下,然后在需要获取父分类的所有子分类的地方使用下面代码:
<?php wp_list_categories( $args = array( 'show_option_all' => '',
'orderby' => 'name',
'use_desc_for_title' => 1,
'child_of' => get_category_root_id($cat),
'optioncount'=>1,
'hierarchical' => 1,
'title_li' => '',
'show_option_none' => __('抱歉,暂无分类。'),
'depth' => 1,
'taxonomy' => 'category',
'walker' => null
));
?>
这样就可以在获取到父分类的所有子分类
文章来源于互联网:WordPress获取当前分类下的所有子分类
clomiphene 60 pills 25 mg no script usa After we get out of this door, let is follow the position of the meteor in the daytime how to sweeten tea without sugar for diabetics Tide Diabetes Drugs and look for it
buy coursework online
coursework masters
coursework online
free sound effects https://sounddeffects.com
samsung ringtones https://downloadfreeringtoness.com/samsung-ringtones
funny ringtones https://downloadfreeringtoness.com/funny-ringtones
best ringtones https://ringtonessbase.com
best ringtones https://ringtonessbase.com
firefox dino https://chromedinos.com
dinosaur game when no internet https://chromedinos.com
r2d2 message tone short https://ringtonessphone.com/r2d2-text-tone.html
narcos ringtone https://ringtonessphone.com/narcos-ringtone.html