最近访客
百度未收录

WordPress获取当前分类的全部子分类

 

WordPress获取当前分类的全部子分类-狐狸库
WordPress

在WordPress分类页显示当前分类下的全有子分类链接,可以用下面的代码:

将下面代码添加到当前主题function.php中:

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

然后在准备显示的位置添加:

<?php wp_list_categories(\'child_of=\' . get_category_root_id($cat) . \'&depth=1&hide_empty=0&hierarchical=1&optioncount=1&title_li=\');?>

代码源自网络,出处未知。

温馨提示:本文最后更新于2022/10/20 12:41:45。若文章内容或图片失效,请留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容