1.现在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); // 将当前分类设为上级分类(往上爬)
}
return $this_category->term_id; // 返回根分类的id号
}

2.然后在页面要显示二级分类的地方粘贴下面这段代码即

<?php
if(is_single()||is_category())
{
if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" )
{
echo '<ul>';
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");
echo '</ul>';
}
}
?>
<?php $args = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC',
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'include' => '',
'hierarchical' => 1,
'title_li' => __( 'Categories' ),
'show_option_none' => __('No categories'),
'number' => null,
'echo' => 1,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => null
); ?>

默认用法输出的效果:

  • 无连接的分类
  • 根据分类名称对分类列表进行升序排列
  • 以无序列表的样式显示
  • 不显示文章数量
  • 只显示有文章的分类
  • 设置标题属性到分类描述
  • 子分类无限制
  • 不显示Feed和Feed图像
  • 不排除任何分类,并包括所有分类
  • 为当前的分类添加CSS类’current-cat’
  • 以分层缩进的方式显示分类列表
  • 在列表的顶部显示“分类(Categories)”作为标题
  • 没有SQL限制(’number’ => 0 is not shown above)
  • 显示(输出)分类
  • 不限制显示的深度
  • 所有分类
  • 使用一个新的Walker_Category 类对象 walker 来显示列表
<?php $args = array(
‘show_option_all’ => “, 无链接的分类
‘orderby’ => ‘name’, 按照分类名排序
‘order’=> ‘ASC’, 升序
‘show_last_update’ => 0, 不显示分类中日志的最新时间戳
‘style’ => ‘list’, 用列表显示分类
‘show_count’ => 0, 0, 不显示分类下的日志数
‘hide_empty’ => 1, Displays only Categories with posts
‘use_desc_for_title’ => 1, 显示分类链接中 title 标签的分类描述
‘child_of’ => 0, 子分类无限制
‘feed’ => ”, 无 feed
‘feed_image’ => ”, 无 feed 图片显示
‘exclude’ => ”, 不在分类列表中显示该分类
‘hierarchical’ => true, 分层显示父/子分类
‘title_li’ => __(‘Categories’), 在列表前作为标题显示分类
‘echo’ => 1 显示分类
); ?>

最新文章

  1. mysql中boolean类型
  2. Delphi dll 断点调试
  3. Linux 查找文件并删除文件内容
  4. BZOJ 3932 [CQOI2015]任务查询系统 ——可持久化线段树
  5. tab模块
  6. 第二百二十三天 how can I 坚持
  7. QT中窗口刷新事件的学习总结
  8. Git打补丁常见问题
  9. MAC图片格式转换
  10. 编写高质量代码:改善Java程序的151个建议(第一章:JAVA开发中通用的方法和准则)
  11. windows 10 防火墙设置规则:允许特定ip端口
  12. js上传图片压缩,并转化为base64
  13. my live boadband
  14. vue里的样式添加之行间样式
  15. 第 8 章 容器网络 - 071 - 如何定制 Calico 的 IP 池?
  16. logstash收集IIS日志
  17. Apache Hadoop YARN: 背景及概述
  18. Oracle EBS SLA 详解(转)
  19. 深入解读《Gartner2017年商业智能和分析平台魔力象限报告》
  20. E. The Supersonic Rocket Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)

热门文章

  1. 深入研究Clang(十) Clang Static Analyzer简介
  2. Spark学习笔记(一)
  3. P1460 健康的荷斯坦奶牛 Healthy Holsteins (简单的dfs)
  4. RF(页面断言)
  5. muduo网络库源码学习————线程安全
  6. Docker docker-compose 配置lnmp开发环境
  7. 10)drf 过滤器(条件查询 排序 ) 分页器
  8. 再谈 PHP 未来之路
  9. E. Count The Blocks(找数学规律)
  10. 牛客小白月赛16 小石的妹子 二分 or 线段树