详解wordpress中显示分类的wp_list_categories()函数的使用
参考文章:http://codex.wordpress.org/Template_Tags/wp_list_categories
注意:wp_list_categories()与WordPress 2.1的list_cats()和wp_list_cats()两个函数类似 ,但推荐使用wp_list_categories()。(这两个函数都不推荐使用)。
Usage 用法
<?php wp_list_categories ( $args ); ?>
参数包括:
<?php $args = array( 'show_option_all' => , 'orderby' => 'name' , 'order' => 'ASC' , 'show_last_update' => 0 , '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' => true , 'title_li' => __ ( 'Categories' ), 'number' => NULL , 'echo' => 1 , 'depth' => 0 , 'current_category' => 0 , 'pad_counts' => 0 , 'taxonomy' => 'category' ); ?>
各个参数使用说明
show_option_all
默认为空,不显示;非空时,将显示首页,例如我们可以这样使用
<?php wp_list_categories('show_option_all=首 页'); ?>
那么首页就显示在分类的最开头
orderby
排序,默认使用name排序,可以使用下面的选项进行排序
* id
* name – Default 名称 -默认
* slug
* count
* term_group
order
* ASC – Default 升序 -默认
* DESC 降序
show_last_updated
( boolean )按上次更新文章时间戳显示(TRUE)或不是(假)。默认为false。
* 1 (True) 1(真)
* 0 (False) – Default 0(假) -默认
style
* list – Default 列表 -默认
* none 无
show_count
是否显示文章数
* 1 (True) 1(真)
* 0 (False) – Default 0(假) -默认
hide_empty
文章数为空的类目是否显示
* 1 (True) – Default 1(真) -默认
* 0 (False) 0(假)
use_desc_for_title
是否显示这个链接的描述,但在2.9.1下测试无效果
* 1 (True) – Default 1(真) -默认
* 0 (False) 0(假)
child_of
显示某个ID分类下的自分类
feed
类目后显示rss订阅,默认无显示,例如
<?php wp_list_categories('feed=rss'); ?>
feed_type
就是在rss地址后在加一层连接,例如原来是http://www.codeif.com/topic/category/soft/feed 加上参数feed_type=2,则变为http://www.codeif.com/topic/category/soft/feed/2
feed_image feed_image
( 字符串 )设置为一个图像的URI(通常是一个RSS feed图标),作为一个供稿链接到每个类别’的RSS – 2此参数覆盖订阅的参数 。这个参数没有默认值
exclude
排除一个或者多个类别,排除多个时用英文逗号隔开
exclude_tree
排除category-tree
include
只包括在一个或多个类别,多个类别用英文逗号隔开
hierarchical
是否分层
* 1 (True) – Default 1(真) -默认
* 0 (False) 0(假)
title_li
设置类目外的名称和风格。 以“Categories”默认值。如果存在而空,外列表项目将不被显示。
number
设置的类别数目显示。这将导致限价值的SQL定义。 Default to no LIMIT.默认为没有限制。
echo
显示结果还是保存到一个变量中(不显示)
* 1 (True) – Default 1(真) -默认
* 0 (False) 0(假)
depth
( 整数 )此参数控制如何在多层次的分类层次结构要分类列入名单。.默认值是0(显示所有的分类及其子分类)。
* 0 -所有类别和子类别(默认)。
* -1 – All Categories displayed in flat (no indent) form (overrides hierarchical ). -1 -所有类别缩进显示在单位(没有)的形式(覆盖层次 )。
* 1 -只显示顶层分类
* n -指定的深度(或级别),以在显示下降
current_category
在指定的类目的<li>下添加current-cat的class,默认为给当前页面添加。
pad_counts
在2.9版本中假如,是否包含自分类下的数目
* 1 (true) 1(真)
* 0 (false) – default 0(假) -默认
taxonomy
分类返回,此参数将在3.0版本有效:
* category – default 分类 -预设
* taxonomy – or any registered taxonomy 分类 -分类或注册
wp_list_categories()位于wp-includes/category-template.php 。
–EOF–
