WordPress:Template Tags/wp list categories

来自站长百科
Fludlen讨论 | 贡献2008年6月30日 (一) 17:33的版本
跳转至: 导航、​ 搜索
可打印版不再被支持且可能有渲染错误。请更新您的浏览器书签并改用浏览器默认的打印功能。

Description

描述

The template tag, wp_list_categories, displays a list of Categories as links. When a Category link is clicked, all the posts in that Category will display on a Category Page using the appropriate Category Template dictated by the Template Hierarchy rules. wp_list_categories works in much the same way as the two template tags replaced in WordPress 2.1, list_cats()(deprecated), and wp_list_cats()(deprecated).

模板标签wp_列表_类别,显示了关于[[WordPress:Glossary#Category|类别]的一个列表作为一个关于链接的列表。当点击一个类别的链接的时候,关于那个类别的所有文章都会显示在类别网页上,使用了模板层级规则规定的适当的类别标签wp_列表_类别 与WordPress2.1中被取代的两个标题的运行方式基本相同, 列表_cats()(取消的),和wp_列表_cats()(取消的)。

== Usage ==

用法

%%% <?php wp_list_categories('arguments'); ?> %%%

%%% <?php wp_list_categories('arguments'); ?> %%%

Examples

例子

Default Usage

默认用法

$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
);


$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
);


By default, the usage shows: 默认情况下,用法显示:

  • No link to all categories
  • 没有链接连接到所有的类别
  • Sorts the list of Categories in by the Category name in ascending order
  • 以升序的方式,根据类别名称,给类别分类。
  • Does not show the last update (last updated post in each Category)
  • 不显示最近的更新(每个类别中的最后更新的文章)
  • Displayed in an unordered list style
  • 以无序的列表样式显示
  • Does not show the post count
  • 不显示文章数目
  • Displays only Categories with posts
  • 只显示拥有文章的类别
  • Sets the title attribute to the Category Description
  • 将标题属性设置为类别描述
  • Is not restricted to the child_of any Category
  • 没有限制到任何类别的子类别_
  • No feed or feed image used
  • 没有使用feed或者feed图像
  • Does not exclude any Category and includes all Categories ('include' => is not shown above)
  • 没有排除任何类别,也没有包含所有的类别('包含' => 没有在上面显示)
  • Shows the Categories in hierarchical indented fashion
  • 以层级嵌套的方式显示类别
  • Display Category as the heading over the list
  • 显示类别为列表上的标题
  • No SQL LIMIT is imposed ('number' => 0 is not shown above)
  • 没有强加SQL 限制('数字' => 没有在上面显示0)
  • Displays (echos) the categories
  • No limit to depth
  • 显示 (echos)类别
  • 对于深度,没有限制
wp_list_categories();

wp_列表_类别();

Include or Exclude Categories

包含或者删除类别

To sort categories alphabetically and include only the categories with IDs of 16, 3, 9 and 5, you could write the following code:

按字母顺序给类别分类,并且只包含ID是16,3,9,和5的类别,你可以写下以下的代码:

<ul>
<?php
wp_list_categories('orderby=name&include=3,5,9,16'); ?>
</ul>


<ul>
<?php
wp_list_categories('orderby=name&include=3,5,9,16'); ?>
</ul>


The following example displays category links sorted by name, shows the number of posts for each category, and excludes the category with the ID of 10 from the list.

下面的例子显示了根据名称分类的类别链接,显示了每个类别的文章数目,并且从列表中删除了ID是10的类别。

<ul>
<?php
wp_list_categories('orderby=name&show_count=1&exclude=10'); ?>
</ul>


<ul>
<?php
wp_列表_类别('orderby=name&show_count=1&exclude=10'); ?>
</ul>


Display or Hide the List Heading

显示或者隐藏列表标题

The title_li parameter sets or hides a title or heading for the category list generated by wp_list_categories. It defaults to '(__('Categories')', i.e. it displays the word "Categories" as the list's heading. If the parameter is set to a null or empty value, no heading is displayed. The following example code excludes categories with IDs 4 and 7 and hides the list heading:

title_liwp_list_categories产生的类别列表设置或者隐藏一个标题或者标头。默认'(__('Categories')',例如,显示单词"类别"作为列表的标题。如果参数设置为零,或者空参数,就不会显示标题。下面的例子代码排除了ID为4和7的类别并且隐藏了列表标题:

<ul>
<?php
wp_list_categories('exclude=4,7&title_li='); ?>
</ul>


<ul>
<?php
wp_list_categories('exclude=4,7&title_li='); ?>
</ul>


In the following example, only Cateogories with IDs 9, 5, and 23 are included in the list and the heading text has been changed to the word "Poetry", with a heading style of <h2>:

在下面的例子中,只有ID是9,5和23的类别包含在列表中,而且标题文本已经更改为"诗",标题样式为<h2>:

<ul>
<?php
wp_list_categories('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>


<ul>
<?php
wp_list_categories('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>


Only Show Children of a Category

只显示子类别

The following example code generates category links, sorted by ID, only for the children of the category with ID 8; it shows the number of posts per category and hides category descriptions from the title attribute of the generated links. Note: If there are no posts in a parent Category, the parent Category will not display.

下面的例子编码产生的类别链接,根据ID分类,只对于ID为8的子类别;显示每个类别的文章数目而且从产生的链接的标题 属性中隐藏了类别描述。注:如果母类别中没有包含文章,就不会显示母类别。

<ul>
<?php wp_list_categories('orderby=id&show_count=1
&use_desc_for_title=0&child_of=8'); ?>
</ul>


<ul>
<?php wp_list_categories('orderby=id&show_count=1
&use_desc_for_title=0&child_of=8'); ?>
</ul>

Display Categories with RSS Feed Links

显示拥有RSS Feed 链接的类别

The following example generates Category links sorted by name, shows the number of posts per Category, and displays links to the RSS feed for each Category.

下面的例子产生的类别链接,是根据名称分类的,显示了每个类别中的文章的数目,而且为每个类别显示了链接,连接到RSS feed。

<ul>
<?php
wp_list_categories('orderby=name&show_count=1&feed=RSS'); ?>
</ul>


<ul>
<?php
wp_list_categories('orderby=name&show_count=1&feed=RSS'); ?>
</ul>

To replace the rss link with a feed icon, you could write: 要用一个feed图标来代替rss链接,你可以编写:

<ul>
<?php
wp_list_categories('orderby=name&show_count=1
&feed_image=/images/rss.gif'); ?>
</ul>


<ul>
<?php
wp_list_categories('orderby=name&show_count=1
&feed_image=/images/rss.gif'); ?>
</ul>


Markup and Styling of Category Lists

类别列表的Markup和样式

By default, wp_list_categories() generates nested unordered lists (ul) within a single list item (li) titled "Categories".

默认情况下,wp_列表_类别()在一个单一的列表item(li)标题为"类别"的内部,产生嵌套的无序列表(ul)。


You can [[WordPress:#Display_or_Hide_the_List_Heading|remove the outermost item and list]] by setting the title_li [[WordPress:#Parameters|parameter]] to an empty string. You'll need to wrap the output in an ordered list (ol) or unordered list yourself (see the examples below). If you don't want list output at all, set the style parameter to none.

你可以通过将title_li [[WordPress:#Parameters|参数]]设置到一个空的字符串中,来[[WordPress:#Display_or_Hide_the_List_Heading|移除最外层的item 和列表]]。你需要自己结果覆盖在一个有序的列表(ol)或者无序的列表上(请看看下面的例子)。如果你不想要这些list output,将样式参数设置为没有

If the category list is generated on a Category Archive page, the list item for that category is marked with the HTML class current-cat. The other list items have no class.

如果类别列表是在类别归档网页上产生的,关于那个类别的list item被标记有HTML class current-cat。其它的list item没有class。

...
<li class="current-cat">
  [You are on this category page]
</li>
<li>
  [Another category]
</li>
...


...
<li class="current-cat">
  [You are on this category page]
</li>
<li>
  [Another category]
</li>
...

You can style that list item with a CSS selector :

你可以使用一个CSS 选择器来设计那个list item:

 .current-cat { ... }

.current-cat { ... }

Parameters

参数

show_option_all
(string) A non-blank values causes the display of a link to all categories if the style is set to list. The default value is not to display a link to all.
显示_所有的_选项
(string)如果样式设置到列表上,一个非空的参数值会导致显示的链接连接到所有的类别中。默认值是不显示连接到所有类别的链接。
orderby
(string) Sort categories alphabetically, by unique Category ID, or by the count of posts in that Category. The default is sort by category name. Valid values:
顺序
(string)根据字母顺序给类别分类,通过独一的类别ID或者通过类别中文章的数目,给类别分类。默认是通过类别名称给类别分类。有效的参数值:
  • ID
  • name - default
  • count
  • ID
  • 名称 - 默认
  • 数目
order
(string) Sort order for categories (either ascending or descending). The default is ascending. Valid values:
顺序
(string)类别的分类顺序(升序或者降序)。默认是升序。有效参数值:
  • ASC - default
  • DESC
  • ASC - 默认
  • DESC
show_last_updated
(boolean) Should the last updated timestamp for posts be displayed (TRUE) or not (FALSE). Defaults to FALSE.
显示_最近_更新
(boolean)最后更新的文章的日期是否应该显示,显示(正确的)或者不显示(错误的)。默认是错误的。
* 1 (true)
* 0 (false) - default
* 1 (正确的)
* 0 (错误的) - 默认
style
(string) Style to display the categories list in. A value of list displays the categories as list items while none generates no special display method (the list items are separated by <br> tags). The default setting is list (creates list items for an unordered list). See the markup section for more. Valid values:
样式
(string)样式用来显示列进的类别。列表的参数值显示类别为list items,然而没有没有产生特别的显示方法(list item由<br>标签分开)。默认设置是列表(为一个无序列表创建了list items)。更多的内容,请看看the markup 部分。有效的参数值:
  • list - default.
  • none
  • 列表 - 默认的。
  • 没有
show_count
(boolean) Toggles the display of the current count of posts in each category. The default is false (do not show post counts). Valid values:
显示_数目
(boolean)显示每个类别中当前文章的数目。默认是错误的(不显示文章数目)。有效的参数值:
  • 1 (true)
  • 0 (false) - default
  • 1 (正确的)
  • 0 (错误的) - 默认
hide_empty
(boolean) Toggles the display of categories with no posts. The default is true (hide empty categories). Valid values:
  • 1 (true) - default
  • 0 (false)
隐藏_空的
(boolean)显示不包含有文章的类别。默认是真的 (隐藏空类别)。有效的参数值:
  • 1 (真的) - 默认
  • 0 (假的)
use_desc_for_title
(boolean) Sets whether a category's description is inserted into the title attribute of the links created (i.e. <a title="<em>Category Description</em>" href="...). The default is true (category descriptions will be inserted). Valid values:
为_标题_使用_desc
(boolean)设置是否将类别的描述插入到创建的链接的标题属性中(例如 <a title="<em>Category Description</em>" href="...)。默认是真的(会插入类别描述)。有效的参数值:
  • 1 (true) - default
  • 0 (false)
  • 1 (真的) - 默认
  • 0 (假的)
child_of
(integer) Only display categories that are children of the category identified by this parameter. There is no default for this parameter. If the parameter is used, the hide_empty parameter is set to false.
子_of
(整数)只显示这个参数识别的类别的子类别。这个参数没有默认值。如果使用了参数,隐藏_空的参数设置为假的
feed (string)
Display a link to each category's rss-2 feed and set the link text to display. The default is no text and no feed displayed.
feed (string)
显示链接连接到每个类别的rss-2 feed并且设置显示链接文本。默认是不显示文本和feed
feed_image
(string) Set a URI for an image (usually an rss feed icon) to act as a link to each categories' rss-2 feed. This parameter overrides the feed parameter. There is no default for this parameter.
feed_图像
(string)为一个图像设置一个URI(通常是一个rss feed 图标)作为链接,连接到每个类别的rss-2 feed。这个参数废除了feed参数。没有关于这个参数的默认值。
exclude
(string) Exclude one or more categories from the results. This parameter takes a comma-separated list of categories by unique ID, in ascending order. See the example. The child_of parameter is automatically set to false.
删除
(string)从结果中删除一个或者更多的类别。这个参数拥有一个唯一的ID的,以逗号分开的类别列表,以升序的顺序。请看看例子中。child_of参数自动设置为假的。
include
(string) Only include the categories detailed in a comma-separated list by unique ID, in ascending order. See the example.
包含
(string)只包含属于某个ID的,在列表中用逗号分开的,以升序排列的类别。请看看例子


hierarchical
(boolean) Display sub-categories as inner list items (below the parent list item) or inline. The default is true (display sub-categories below the parent list item). Valid values:
  • 1 (true) - default
  • 0 (false)

;层级的:(boolean)将子类别显示为内部列表内部(在母类别列表item的下面)或者内联的。默认是真的(在母类别item下面显示子类别)。有效的参数值:

  • 1 (真的) - 默认的
  • 0 (错误的)
title_li
(string) Set the title and style of the outer list item. Defaults to "_Categories". If present but empty, the outer list item will not be displayed. See below for [[WordPress:#Display or Hide the List Heading|examples]].
标题_li
(string)设置外部列表item的标题和样式。默认为"_类别"。如果呈现了,但是是空的,就不会显示外部列表item 。请看看下面的[[WordPress:#Display or Hide the List Heading|例子]]。
number
(integer) Sets the number of Categories to display. This causes the SQL LIMIT value to be defined. Default to no LIMIT.
数字
(整数)设置需要显示多少个类别。这定义了SQL LIMIT 参数值。默认没有LIMIT。
echo
(boolean) Show the result or keep it in a variable. The default is true (display the categories organized). Valid values:
echo
(boolean)显示了结果或者将结果保存在一个变数中。默认是真的(显示组织好的类别)。有效的参数值:
  • 1 (true) - default
  • 0 (false)
  • 1 (正确的) - 默认
  • 0 (错误的)
depth
(integer) This parameter controls how many levels in the hierarchy of Categories are to be included in the list of Categories. The default value is 0 (display all Categories and their children). This parameter added at WordPress:Version 2.5
深度
(整数)这个参数控制了,类别的列表中包含的类别拥有多少个层级。默认值是0(显示所有的类别和所有的子类别)。这个参数添加在2.5版本
  • 0 - All Categories and child Categories (Default).
  • 0 -所有的类别和子类别(默认)。
  • -1 - All Categories displayed in flat (no indent) form (overrides hierarchical).
  • -1 -所有的类别显示为flat(而不是缩进)形式(取消层级)。
  • 1 - Show only top level Categories
  • 1 -只显示最高级别的类别
  • n - Value of n (some number) specifies the depth (or level) to descend in displaying Categories
  • n -n的值(某个数字)规定了显示的类别的深度(或者层级)

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,

模板:Query String Tag Footer

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.

相关的

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>
Categories: [[WordPress:#Examples|WordPress]] [[WordPress:#Examples|Computers]] [[WordPress:#Examples|Blogging]]
类别: [[WordPress:#Examples|WordPress]] [[WordPress:#Examples|电脑]] [[WordPress:#Examples|写博客]]

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>

This post is in: [[WordPress:#Examples|WordPress]], [[WordPress:#Examples|Computers]], [[WordPress:#Examples|Blogging]]


This post is in: [[WordPress:#Examples|WordPress]], [[WordPress:#Examples|电脑]], [[WordPress:#Examples|写博客]]


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(' &gt; '); ?></p>

<p>Categories: <?php the_category(' &gt; '); ?></p>

Categories: [[WordPress:#Examples|WordPress]] > [[WordPress:#Examples|Computers]] > [[WordPress:#Examples|Blogging]]
类别: [[WordPress:#Examples|WordPress]] > [[WordPress:#Examples|电脑]] > [[WordPress:#Examples|写博客]]

Separated by a Bullet

用Bullet分开

Displays links to categories with a bullet (•) separating the categories.

使用bullet (•)分开类别,显示类别链接

%%%

Post Categories: <?php the_category(' &bull; '); ?>

%%% %%%

文章类别: <?php the_category(' &bull; '); ?>

%%%

Post Categories: [[WordPress:#Examples|WordPress]] • [[WordPress:#Examples|Computers]] • [[WordPress:#Examples|Blogging]]
文章类别: [[WordPress:#Examples|WordPress]] • [[WordPress:#Examples|电脑]] • [[WordPress:#Examples|写博客]]

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,

模板:PHP Function Tag Footer


相关的

模板:标签类别标签

模板:PHP 函数标签页底文字

模板:查询 字符串 标签 页底文字

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.