WordPress:Template Tags/wp list categories
目录 |
描述
模板标签wp_list_categories,显示了关于类别的一个列表作为一个关于链接的列表。当点击一个类别的链接的时候,关于那个类别的所有文章都会显示在类别网页上,使用了模板层级规则规定的适当的类别标签。wp_list_categories 与WordPress2.1中被取代的两个标题的运行方式基本相同, list_cats()(取消的),和wp_list_cats()(取消的)。
用法
%%% <?php wp_list_categories('arguments'); ?> %%%
例子
默认用法
$defaults = 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_image' => '', 'exclude' => '', 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0 );
默认情况下,用法显示:
- 没有链接连接到所有的类别
- 以升序的方式,根据类别名称,给类别分类。
- 不显示最近的更新(每个类别中的最后更新的文章)
- 以无序的列表样式显示
- 不显示文章数目
- 只显示拥有文章的类别
- 将标题属性设置为类别描述
- 没有限制到任何类别的子类别_
- 没有使用feed或者feed图像
- 没有排除任何类别,也没有包含所有的类别('include' => 没有在上面显示)
- 以层级嵌套的方式显示类别
- 显示类别为列表上的标题
- 没有强加SQL 限制('数字' => 没有在上面显示0)
- 显示 (echos)类别
- 对于深度,没有限制
wp_list_categories();
包含或者删除类别
按字母顺序给类别分类,并且只包含ID是16,3,9,和5的类别,你可以写下以下的代码:
<ul>
<?php
wp_list_categories('orderby=name&include=3,5,9,16'); ?>
</ul>
下面的例子显示了根据名称分类的类别链接,显示了每个类别的文章数目,并且从列表中删除了ID是10的类别。
<ul>
<?php
wp_list_categories('orderby=name&show_count=1&exclude=10'); ?>
</ul>
显示或者隐藏列表标题
title_li为wp_list_categories产生的类别列表设置或者隐藏一个标题或者标头。默认'(__('Categories')',例如,显示单词"类别"作为列表的标题。如果参数设置为零,或者空参数,就不会显示标题。下面的例子代码排除了ID为4和7的类别并且隐藏了列表标题:
<ul>
<?php
wp_list_categories('exclude=4,7&title_li='); ?>
</ul>
在下面的例子中,只有ID是9,5和23的类别包含在列表中,而且标题文本已经更改为"诗",标题样式为<h2>:
<ul>
<?php
wp_list_categories('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>
只显示子类别
下面的例子编码产生的类别链接,根据ID分类,只对于ID为8的子类别;显示每个类别的文章数目而且从产生的链接的标题 属性中隐藏了类别描述。注:如果母类别中没有包含文章,就不会显示母类别。
<ul>
<?php wp_list_categories('orderby=id&show_count=1
&use_desc_for_title=0&child_of=8'); ?>
</ul>
显示拥有RSS Feed 链接的类别
下面的例子产生的类别链接,是根据名称分类的,显示了每个类别中的文章的数目,而且为每个类别显示了链接,连接到RSS feed。
<ul>
<?php
wp_list_categories('orderby=name&show_count=1&feed=RSS'); ?>
</ul>
要用一个feed图标来代替rss链接,你可以编写:
<ul>
<?php
wp_list_categories('orderby=name&show_count=1
&feed_image=/images/rss.gif'); ?>
</ul>
类别列表的Markup和样式
默认情况下,wp_list_categories()在一个单一的列表item(li)标题为"类别"的内部,产生嵌套的无序列表(ul)。
你可以通过将title_li 参数设置到一个空的字符串中,来移除最外层的item 和列表。你需要自己覆盖结果在一个有序的列表(ol)或者无序的列表上(请看看下面的例子)。如果你不想要这些list output,将样式参数设置为none。
如果类别列表是在类别归档网页上产生的,关于那个类别的list item被标记有HTML class current-cat。其它的list item没有class。
... <li class="current-cat"> [You are on this category page] </li> <li> [Another category] </li> ...
你可以使用一个CSS 选择器来设计那个list item:
.current-cat { ... }
参数
- show_option_all
- (string)如果样式设置到列表上,一个非空的参数值会导致显示的链接连接到所有的类别中。默认值是不显示连接到所有类别的链接。
- orderby
- (string)根据字母顺序给类别分类,通过独一的类别ID或者通过类别中文章的数目,给类别分类。默认是通过类别名称给类别分类。有效的参数值:
- ID
- name - default
- count
- order
- (string) 类别的分类顺序(升序或者降序)。默认是升序。有效参数值:
- ASC - default
- DESC
- show_last_updated
- (boolean) 最后更新的文章的日期是否应该显示,显示(TRUE) 或者不显示 (FALSE).默认是 FALSE.
- * 1 (true)
- * 0 (false) - default
- style
- (string)样式用来显示列表的类别。列表的参数值显示类别为list items,然而none没有产生特别的显示方法(list item由<br>标签分开)。默认设置是列表(为一个无序列表创建了list items)。更多的内容,请看看the markup 部分。有效的参数值:
- list - 默认的。
- none
- show_count
- (boolean)显示每个类别中当前文章的数目。默认是错误的(不显示文章数目)。有效的参数值:
- 1 (true)
- 0 (false) - default
- hide_empty
- (boolean) 显示不包含有文章的类别。默认是真的 (隐藏空类别)。有效的参数值:
- 1 (true) - 默认
- 0 (false)
- use_desc_for_title
- (boolean)设置是否将类别的描述插入到创建的链接的标题属性中(例如 <a title="<em>Category Description</em>" href="...)。默认是true(会插入类别描述)。有效的参数值:
- 1 (true) - default
- 0 (false)
- child_of
- (integer) 只显示这个参数识别的类别的子类别。这个参数没有默认值。如果使用了参数, the hide_empty 参数设置为 false.
- feed (string)
- 显示链接连接到每个类别的rss-2 feed并且设置显示链接文本。默认是不显示文本和feed。
- feed_image
- (string)为一个图像设置一个URI(通常是一个rss feed 图标)作为链接,连接到每个类别的rss-2 feed。这个参数废除了feed参数。没有关于这个参数的默认值。
- 删除
- (string)从结果中删除一个或者更多的类别。这个参数拥有一个唯一的ID的,以逗号分开的类别列表,以升序的顺序。请看看例子中。child_of参数自动设置为假的。
- 包含
- (string)只包含属于某个ID的,在列表中用逗号分开的,以升序排列的类别。请看看例子。
- hierarchical
- (boolean)将子类别显示为内部列表内部(在母类别列表item的下面)或者内联的。默认是真的(在母类别item下面显示子类别)。有效的参数值:
- 1 (true) - default
- 0 (false)
- title_li
- (string)设置外部列表item的标题和样式。默认为"_类别"。如果呈现了,但是是空的,就不会显示外部列表item 。请看看下面的例子。
- number
- (integer)设置需要显示多少个类别。这定义了SQL LIMIT 参数值。默认没有LIMIT。
- echo
- (boolean) 显示了结果或者将结果保存在一个变数中。默认是真的(显示组织好的类别)。有效的参数值:
- 1 (true) - default
- 0 (false)
- depth
- (integer) 这个参数控制了,类别的列表中包含的类别拥有多少个层级。默认值是0(显示所有的类别和所有的子类别)。这个参数添加在2.5版本中
- 0 -所有的类别和子类别(默认)。
- -1 -所有的类别显示为flat(而不是缩进)形式(取消层级)。
- 1 -只显示最高级别的类别
- n -n的值(某个数字)规定了显示的类别的深度(或者层级)
相关的
Description
描述
Displays a link to the category or categories a post belongs to. This tag must be used within WordPress:The Loop.
显示文章所属的类别的连接。必须在The Loop内,使用这个标签。
Usage
用法
%%% <?php the_category('separator', 'parents' ); ?> %%% %%% <?php the_category('separator', 'parents' ); ?> %%%
Examples
Separated by Space
例子
由空格分开
This usage lists categories with a space as the separator.
这个用法用分隔符,隔开类别,列出。
<p>Categories: <?php the_category(' '); ?></p>
<p>Categories: <?php the_category(' '); ?></p>
Separated by Comma
用逗号分开
Displays links to categories, each category separated by a comma (if more than one).
显示类别连接,(如果多于一个类别)类别之间用逗号分开。
<p>This post is in: <?php the_category(', '); ?></p>
<p>This post is in: <?php the_category(', '); ?></p>
Separated by Arrow
用箭头分开
Displays links to categories with an arrow (>) separating the categories. (Note: Take care when using this, since some viewers may interpret a category following a > as a subcategory of the one preceding it.)
用箭头显示类别链接(>)分开类别。(注: 使用这种方法的时候,应该注意,有的访客认为类别后面的> 是前面类别的子类别。)
<p>Categories: <?php the_category(' > '); ?></p>
<p>Categories: <?php the_category(' > '); ?></p>
Separated by a Bullet
用Bullet分开
Displays links to categories with a bullet (•) separating the categories.
使用bullet (•)分开类别,显示类别链接
%%%Post Categories: <?php the_category(' • '); ?>
%%% %%%文章类别: <?php the_category(' • '); ?>
%%%Parameters
参数
- separator
- (string) Text or character to display between each category link. The default is to place the links in an unordered list.
;分隔符: (string)链接类别之间显示的文本或者字符。默认是将链接放在无序列表上。
- parents
- (string) How to display links that reside in child (sub) categories. Options are:
- parents
- (string)怎样显示子类别中的链接。选项有:
- 'multiple' - Display separate links to parent and child categories, exhibiting "parent/child" relationship.
- 'multiple' -分开显示母类别和子类别的链接,显示为"母/子"关系。
- 'single' - Display link to child category only, with link text exhibiting "parent/child" relationship.
- 'single' -只显示子类别链接,链接文本显示为"母/子"关系。
- Note: Default is a link to the child category, with no relationship exhibited.
:注:默认是链接到子类别的一个链接,不显示关系。
Related
the_category, the_category_rss, single_cat_title, category_description, wp_dropdown_categories, wp_list_categories, in_category, get_category_parents, get_the_category get_category_link,
Template:PHP Function Tag Footer
相关的
This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.