wp_list_categories() 可以将wordpress网站的文章分类以列表链接的形式显示出来。点击各个分类链接,就可以进入到wordpress网站的文章分类列表页面。在wordpress主题开发时,我们也可以通过wp_list_categories() 函数来创建网站的某个菜单导航。

语法:

<?php wp_list_categories( $args ); ?>

参数组成:

$args = array(

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’show_option_all\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//是否列出分类链接

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’orderby\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’name\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//分类列表按什么排序,这里是按名称排列

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’order\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ASC\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//分类列表的排序,这里是升序;DESC – 降序

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’style\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’list\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//是否用列表样式(ul>li)

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’show_count\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 0,//是否在分类侧边显示该分类的文章数量,0表示不显示

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’hide_empty\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 1,//是否隐藏没有日志的分类

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’use_desc_for_title\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 1,//是否显示分类描述

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’child_of\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 0,//子分类是否显示

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’exclude\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//排除分类的ID,多个用\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,(英文逗号)\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’分隔

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’exclude_tree\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//排除分类树,即父分类及其下的子分类

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’include\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//不排除的分类,即显示的分类

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’hierarchical\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => true,//是否将子、父分类分级

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’title_li\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => __( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’Categories\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ),//列表标题的名称

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’show_option_none\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => __(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’No categories\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’),//无分类时显示的标题

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => null,//显示多少个分类

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’echo\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 1,//是否显示,显示或者返回字符串

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’depth\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 0,//层级限制

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’current_category\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => 0,//添加一个没有的分类

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’taxonomy\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’category\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,//使用的分类法

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’walker\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ => null//用于显示的类

};

部分参数详解:

style:分类列表显示的样式。默认设置为列表(无序列表)。有效值:list(默认)和 none。

hide_empty:是否显示无文章分类。 默认不显示无文章分类。有效值: 1(True) 默认和0 (False)

use_desc_for_title:是否将分类描述作为分类链接中的 title 属性,默认为 true。

child_of:(整数)只显示此参数确定的分类的子分类。

exclude:排除的分类ID。使用英文逗号分隔分类ID。参数 include 必须为空。

exclude_tree:排除分类树。使用英文逗号分隔多个分类ID。参数 include 必须为空。如果 hierarchical 参数 为 true ,请使用 exclude 参数替代 exclude_tree 。

include:只显示特定的分类,使用英文逗号分隔多个分类ID。

depth:显示分类的深度(即显示多少层的子分类)。有效值:

0 :显示所有分类和子分类(默认)

-1 :不按层级缩进显示(不缩进)(覆盖hierarchical)。

1 :只显示顶级分类

n :根据n的具体数字来显示对应等级的分类。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部