wordpress调用当前分类的全部子分类
作者:admin 日期:2022-03-13
wordpress在制作企业主题的时候比较常遇到要调用当前分类下的全部子分类。要实现这个可以按照以下步骤操作。
首先在主题的“functions.php”里面写个函数,代码如下:
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);
- }
- return $this_category->term_id;
- }
然后在需要调用的页面里写以下代码:
PHP代码
- <?php
- if(is_category()) {
- $cat = get_query_var('cat');
- $categoryurl = get_category_link($cat);
- if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" ) {
- 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");
- }
- }
- ?>
最后自己调整下css就ok了。
上一篇: WinHttpRequest SetProxy 方法详解,设置代理服务器信息
下一篇: WordPress函数:wp_list_categories(分类列表)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: wordpress
相关日志:
下一篇: WordPress函数:wp_list_categories(分类列表)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: wordpress
相关日志:
评论: 0 | 引用: 0 | 查看次数: 152
发表评论
广告位