WordPress代码实现分类页导航栏显示二级栏目

在函数文件添加下述代码:

function get_category_root_id($cat) {
// 取得当前分类
$this_category = get_category($cat);
// 若当前分类有上级分类时循环
while($this_category->category_parent) {
// 将当前分类设为上级分类
$this_category = get_category($this_category->category_parent);
}
// 返回根分类的id号
return $this_category->term_id;
}

接着在分类头部添加:

<div class=”csj_country”>
<li class=”cat-item cat-item-1″><a href=”/”>首页</a></li>
<?php wp_list_categories(‘child_of=’ . get_category_root_id($cat) . ‘&depth=1&hide_empty=0&hierarchical=1&optioncount=1&title_li=’);?>
</div>

 

QQ咨询 微信号微信公众号 返回顶部