关于wordpress的分类页面如何调用子分类,谁能帮忙分析下

目前有3级分类:
家电,冰箱,智能冰箱
家电,冰箱,节能冰箱
家电,电视,智能电视
家电,空调,智能空调

现在我使用以下代码可以调取出当前分类的所有子分类
家电:冰箱,智能冰箱,节能冰箱,空调,智能空调,电视,智能电视

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号
}

    <?php  
  
if(get_query_var("cat"))  
{  
echo '<ul class="soncategory">';  
echo '<li class="categorytext">分类:</li>';
echo wp_list_categories("child_of=" . get_query_var("cat") . "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC");  
echo '</ul>';  
}?>

哪里出问题了,我只想调用当前分类的子分类,如
家电:电视,空调,冰箱
冰箱:节能冰箱,智能冰箱

要如何实现

阅读 2.4k
1 个回答

好吧,解决了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题