WordPress: Template Tags/wp dropdown categories:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: {{Copyedit}} == Description == Displays a list of categories in a select (i.e dropdown) box with no submit button. == Usage == %%% <?php wp_dropdown_categories('arguments'); ?> %%% == E...)
 
无编辑摘要
第1行: 第1行:
{{Copyedit}}
{{Copyedit}}
{{Copyedit}}
== Description ==
== Description ==
==描述 ==
Displays a list of categories in a select (i.e dropdown) box with no submit button.
Displays a list of categories in a select (i.e dropdown) box with no submit button.
在一个没有提交按钮的选择框(如下拉列表)上显示类别的一个列表。


== Usage ==
== Usage ==
== 用法 ==
%%% <?php wp_dropdown_categories('arguments'); ?> %%%
%%% <?php wp_dropdown_categories('arguments'); ?> %%%
%%% <?php wp_dropdown_categories('arguments'); ?> %%%


== Examples ==
== Examples ==
===Default Usage===
===Default Usage===
==例子==
===默认用法===
<pre>
<pre>
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID',  
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID',  
第14行: 第23行:
'name' => 'cat', 'class' => 'postform', 'depth' => 0);
'name' => 'cat', 'class' => 'postform', 'depth' => 0);
</pre>
</pre>
<pre>
$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID',
'顺序' => 'ASC', '显示_最后的_更新' => 0, '显示_数目' => 0, '隐藏_空的' => 1,
'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0,
'名称' => 'cat', 'class' => 'postform', 'depth' => 0);
</pre>
By default, the usage shows:
By default, the usage shows:
默认情况下,用法是:
* Sorts by category id in ascending order
* Sorts by category id in ascending order
*以上升的顺序,根据类别id分类
* Does not show the last date updated
* Does not show the last date updated
*不显示最后一次的更新
* Does not show the count of posts within a category
* Does not show the count of posts within a category
*不显示一个类别内文章的数目
* Does not show 'empty' categories
* Does not show 'empty' categories
* 不显示 '空' 类别
* Excludes nothing
* Excludes nothing
*不排除任何内容
* Displays (echos) the categories
* Displays (echos) the categories
* No category is 'selected' in the form
*显示(echos)类别
 
* No category is 'selected' in the form‘
*没有从形式上'选择'类别‘
 
* Does not display the categories in a hierarchical structure  
* Does not display the categories in a hierarchical structure  
*不以等级结构显示类别
* Assigns 'cat' to the form name
* Assigns 'cat' to the form name
*将'cat'指定为格式名
* Assigns the form to the class 'postform'
* Assigns the form to the class 'postform'
*将格式指定到级别'平台'
* No depth limit
* No depth limit
*没有深入的限制


  <?php wp_dropdown_categories(); ?>
  <?php wp_dropdown_categories(); ?>
<?php wp_dropdown_categories(); ?>


===Dropdown with Submit Button===
===Dropdown with Submit Button===
===拥有提交按钮的下拉列表===
Displays a hierarchical category dropdown list in HTML form with a submit button, in a WordPress sidebar unordered list, with a count of posts in each category.
Displays a hierarchical category dropdown list in HTML form with a submit button, in a WordPress sidebar unordered list, with a count of posts in each category.
以HTML的形式,拥有一个提交按钮,显示一个等级类别的下拉列表,在WordPress工具条中无序的列表上,显示每个类别的文章数目。


  &lt;li id="categories"&gt;
  &lt;li id="categories"&gt;
  &lt;h2&gt;<?php _e('Categories:'); ?>&lt;/h2&gt;
    &lt;form action="<?php bloginfo('url'); ?>" method="get"&gt;
    <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?>
    &lt;input type="submit" name="submit" value="view" /&gt;
    &lt;/form&gt;
&lt;/li&gt;
&lt;li id="categories"&gt;
   &lt;h2&gt;<?php _e('Categories:'); ?>&lt;/h2&gt;
   &lt;h2&gt;<?php _e('Categories:'); ?>&lt;/h2&gt;
     &lt;form action="<?php bloginfo('url'); ?>" method="get"&gt;
     &lt;form action="<?php bloginfo('url'); ?>" method="get"&gt;
第41行: 第104行:


===Dropdown without a Submit Button using JavaScript===
===Dropdown without a Submit Button using JavaScript===
===使用JavaScript没有提交按钮的下拉列表===
Example depicts using the show_option_none parameter and was gleaned from [http://wordpress.org/support/topic/145489?replies=13#post-657759 Moshu's forum post].
Example depicts using the show_option_none parameter and was gleaned from [http://wordpress.org/support/topic/145489?replies=13#post-657759 Moshu's forum post].
例子描述了使用show_option_none参数而且是从[http://wordpress.org/support/topic/145489?replies=13#post-657759 Moshu的论坛文章]中收集的。
<pre>
<pre>
<pre>
<li id="categories"><h2><?php _e('Posts by Category'); ?></h2>
<?php wp_dropdown_categories('show_option_none=Select category'); ?>
<script type="text/javascript"><!--
    var dropdown = document.getElementById("cat");
    function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home');
?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
}
    }
    dropdown.onchange = onCatChange;
--></script>
</li>
<li>
</pre>
<li id="categories"><h2><?php _e('Posts by Category'); ?></h2>
<li id="categories"><h2><?php _e('Posts by Category'); ?></h2>
<?php wp_dropdown_categories('show_option_none=Select category'); ?>
<?php wp_dropdown_categories('show_option_none=Select category'); ?>
第59行: 第149行:
<li>
<li>
</pre>
</pre>


===Dropdown without a Submit Button using JavaScript (2)===
===Dropdown without a Submit Button using JavaScript (2)===
===使用JavaScript没有提交按钮的下拉列表 (2)===
In this example the ''echo'' parameter (echo=0) is used. A simple ''preg_replace'' inserts the JavaScript code. It even works without JavaScript (submit button is wrapped by ''noscript'' tags).
In this example the ''echo'' parameter (echo=0) is used. A simple ''preg_replace'' inserts the JavaScript code. It even works without JavaScript (submit button is wrapped by ''noscript'' tags).
这个例子使用了''echo'' 参数 (echo=0)。一个简单的''preg_replace''插入了JavaScript代码。设置没有JavaScript也能够运行(提交按钮被''noscript''标签覆盖)。
<pre>
<li id="categories">
<h2><?php _e('Posts by Category'); ?></h2>
<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form>
</li>
</pre>
<pre>
<pre>
<li id="categories">
<li id="categories">
第75行: 第188行:
</li>
</li>
</pre>
</pre>


== Parameters ==
== Parameters ==
== 参数==


; show_option_all : (''string'') Causes the HTML for the dropdown to allow you to select All of the categories.
; show_option_all : (''string'') Causes the HTML for the dropdown to allow you to select All of the categories.
;显示_所有_选项:(''string'')导致下拉列表的HTML,允许你选择所有的类别。
; show_option_none : (''string'') Causes the HTML for the dropdown to allow you to select NONE of the categories.
; show_option_none : (''string'') Causes the HTML for the dropdown to allow you to select NONE of the categories.
; 不_显示_选项 : (''string'')导致下拉列表的HTML,允许你不选择类别。
; orderby : (''string'') Key to sort options by. Valid values:
; orderby : (''string'') Key to sort options by. Valid values:
;顺序:(''string'')给选项分类的关键词。有效的参数值:
:* <tt>'ID'</tt> (Default)
:* <tt>'ID'</tt> (Default)
:* <tt>'name'</tt>
:* <tt>'name'</tt>
:* <tt>'ID'</tt> (默认)
:* <tt>'名称'</tt>
; order : (''string'') Sort order for options. Valid values:
; order : (''string'') Sort order for options. Valid values:
;顺序: (''string'')选项的分类顺序。有效的参数值:
:* <tt>'ASC'</tt> (Default)
:* <tt>'ASC'</tt> (Default)
:* <tt>'DESC'</tt>
:* <tt>'DESC'</tt>
:* <tt>'ASC'</tt> (默认的)
:* <tt>'DESC'</tt>
; show_last_update : (''boolean'') Sets whether to display the date of the last post in each category. Valid values:
; show_last_update : (''boolean'') Sets whether to display the date of the last post in each category. Valid values:
;显示_最后的_更新:(''boolean'')设置是否在每个类别上显示最后一篇文章的日期。有效的参数值:
:* <tt>1</tt> (True)  
:* <tt>1</tt> (True)  
:* <tt>0 </tt> (False - Default)
:* <tt>0 </tt> (False - Default)
:* <tt>1</tt> (正确的)
:* <tt>0 </tt> (错误的 – 默认)
; show_count : (''boolean'') Sets whether to display a count of posts in each category. Valid values:
; show_count : (''boolean'') Sets whether to display a count of posts in each category. Valid values:
;显示_数目:(''boolean'')设置是否显示每个类别中的文章的数目。有效的参数值:
:* <tt>1</tt> (True)
:* <tt>1</tt> (True)
:* <tt>0</tt> (False - Default)
:* <tt>0</tt> (False - Default)
:* <tt>1</tt> (正确的)
:* <tt>0</tt> (错误的 – 默认)
; hide_empty : (''boolean'') Sets whether to hide (not display) categories with no posts. Valid values:
; hide_empty : (''boolean'') Sets whether to hide (not display) categories with no posts. Valid values:
;隐藏_空的: (''boolean'')设置是否隐藏(不显示)不包含有文章的类别。有效的参数值:
:* <tt>1</tt> (True - Default)
:* <tt>1</tt> (True - Default)
:* <tt>0</tt> (False)
:* <tt>0</tt> (False)
:* <tt>1</tt> (正确的 – 默认)
:* <tt>0</tt> (错误的)
; child_of : (''integer'') Only display categories that are children of the category identified by its ID. There is no default for this parameter.  
; child_of : (''integer'') Only display categories that are children of the category identified by its ID. There is no default for this parameter.  
;子:(''整数'')只显示类别ID识别的子类别。这个参数没有默认值。
; exclude : (''string'') Comma separated list of category IDs to exclude. For example, 'exclude=4,12' means category IDs 4 and 12 will NOT be displayed/echoed or returned. Defaults to exclude nothing.
; exclude : (''string'') Comma separated list of category IDs to exclude. For example, 'exclude=4,12' means category IDs 4 and 12 will NOT be displayed/echoed or returned. Defaults to exclude nothing.
;移除:(''string'')用逗号分开要删除的类别的ID。例如,'删除=4,12',指的是类别IDs4和12不会被显示/echoed或者返回。默认不删除任何类别。
; echo : (''boolean'') Display bookmarks (<tt>TRUE</tt>) or return them for use by PHP (<tt>FALSE</tt>). Defaults to <tt>TRUE</tt>.
; echo : (''boolean'') Display bookmarks (<tt>TRUE</tt>) or return them for use by PHP (<tt>FALSE</tt>). Defaults to <tt>TRUE</tt>.
:* <tt>1</tt> (True - default)
:* <tt>1</tt> (True - default)
; echo : (''boolean'')显示书签(<tt>正确的</tt>)或者返回书签供PHP使用(<tt>错误的</tt>)。默认<tt>真确的</tt>。
:* <tt>1</tt> (正确的 – 默认)
:* <tt>0</tt> (False)
:* <tt>0</tt> (False)
:* <tt>0</tt> (错误的)
; selected : (''integer'') Category ID of the category to be 'selected' or presented in the display box. Defaults to no category selected.
; selected : (''integer'') Category ID of the category to be 'selected' or presented in the display box. Defaults to no category selected.
;选择的:(''整数'')要被'挑选'或者显示在展示框中的类别的类别ID。默认不选择任何类别。
; hierarchical : (''boolean'') Display categories in hierarchical fashion (child categories show indented). Defaults to <tt>FALSE</tt>.
; hierarchical : (''boolean'') Display categories in hierarchical fashion (child categories show indented). Defaults to <tt>FALSE</tt>.
;等级的 : (''boolean'')以等级级别的方式显示类别(子类别以嵌套的方式显示)。默认<tt>错误的</tt>。
:* <tt>1</tt> (True)
:* <tt>1</tt> (True)
:* <tt>1</tt> (正确的)
:* <tt>0</tt> (False - Default)
:* <tt>0</tt> (False - Default)
:* <tt>0</tt> (错误的 – 默认)
; name : (''string'') Name assigned to the dropdown form. Defaults to 'cat'.
; name : (''string'') Name assigned to the dropdown form. Defaults to 'cat'.
; 姓名 : (''string'')给下拉列表指定的形式的名称。默认为'cat'。
; class : (''string'') Class assinged to the dropdown form. Defaults to 'postform'.
; class : (''string'') Class assinged to the dropdown form. Defaults to 'postform'.
;类别:(''string'')指定给下拉列表形式的类别。默认为'文章形式'。
; 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]]
; 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''(显示所有的类别和子类别)。这个参数在[[WordPress:Version 2.5|2.5版本]]时添加的。
:* <tt>0</tt>  - All Categories and child Categories (Default).
:* <tt>0</tt>  - All Categories and child Categories (Default).
:* <tt>0</tt>  -所有的类别和子类别(默认)。
:* <tt>-1</tt> - All Categories displayed in flat (no indent) form (overrides '''hierarchical''').
:* <tt>-1</tt> - All Categories displayed in flat (no indent) form (overrides '''hierarchical''').
:* <tt>-1</tt> -所有的类别以平常格式(而不是缩进格式)显示(删除'''等级级别''')。
:* <tt>1</tt>  - Show only top level Categories
:* <tt>1</tt>  - Show only top level Categories
:* <tt>n</tt>  - Value of n (some number) specifies the depth (or level) to descend in displaying Categories
:* <tt>n</tt>  - Value of n (some number) specifies the depth (or level) to descend in displaying Categories
:* <tt>1</tt>  -只显示最高级别的类别
:* <tt>n</tt>  - n 值(某个数目)规定显示类别的时候,可以显示的子类别的层级(或者等级)


== Related ==
== Related ==
第117行: 第310行:


{{PHP Function Tag Footer}}
{{PHP Function Tag Footer}}
== 相关的 ==
{{标签 类别 标签}}
{{PHP函数 标签 页底文字}}

2008年6月28日 (六) 17:11的版本

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

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

Description

描述

Displays a list of categories in a select (i.e dropdown) box with no submit button.

在一个没有提交按钮的选择框(如下拉列表)上显示类别的一个列表。

Usage

用法

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

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

Examples

Default Usage

例子

默认用法

$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID', 
'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 
'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 
'name' => 'cat', 'class' => 'postform', 'depth' => 0);


$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID', 
'顺序' => 'ASC', '显示_最后的_更新' => 0, '显示_数目' => 0, '隐藏_空的' => 1, 
'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 
'名称' => 'cat', 'class' => 'postform', 'depth' => 0);


By default, the usage shows:

默认情况下,用法是:

  • Sorts by category id in ascending order
  • 以上升的顺序,根据类别id分类
  • Does not show the last date updated
  • 不显示最后一次的更新
  • Does not show the count of posts within a category
  • 不显示一个类别内文章的数目
  • Does not show 'empty' categories
  • 不显示 '空' 类别


  • Excludes nothing
  • 不排除任何内容
  • Displays (echos) the categories
  • 显示(echos)类别
  • No category is 'selected' in the form‘
  • 没有从形式上'选择'类别‘
  • Does not display the categories in a hierarchical structure
  • 不以等级结构显示类别
  • Assigns 'cat' to the form name
  • 将'cat'指定为格式名
  • Assigns the form to the class 'postform'
  • 将格式指定到级别'平台'
  • No depth limit
  • 没有深入的限制
<?php wp_dropdown_categories(); ?>

<?php wp_dropdown_categories(); ?>

Dropdown with Submit Button

拥有提交按钮的下拉列表

Displays a hierarchical category dropdown list in HTML form with a submit button, in a WordPress sidebar unordered list, with a count of posts in each category.

以HTML的形式,拥有一个提交按钮,显示一个等级类别的下拉列表,在WordPress工具条中无序的列表上,显示每个类别的文章数目。

<li id="categories">
 <h2><?php _e('Categories:'); ?></h2>
   <form action="<?php bloginfo('url'); ?>" method="get">
   <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?>
   <input type="submit" name="submit" value="view" />
   </form>
</li>

<li id="categories">

 <h2><?php _e('Categories:'); ?></h2>
   <form action="<?php bloginfo('url'); ?>" method="get">
   <?php wp_dropdown_categories('show_count=1&hierarchical=1'); ?>
   <input type="submit" name="submit" value="view" />
   </form>
</li>

Dropdown without a Submit Button using JavaScript

使用JavaScript没有提交按钮的下拉列表

Example depicts using the show_option_none parameter and was gleaned from Moshu's forum post.

例子描述了使用show_option_none参数而且是从Moshu的论坛文章中收集的。

<pre>

<li id="categories"><h2><?php _e('Posts by Category'); ?></h2>
	<?php wp_dropdown_categories('show_option_none=Select category'); ?>

<script type="text/javascript"><!--
    var dropdown = document.getElementById("cat");
    function onCatChange() {
		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
			location.href = "<?php echo get_option('home');
?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
		}
    }
    dropdown.onchange = onCatChange;
--></script>
</li>
<li>


  • <?php _e('Posts by Category'); ?>

    <?php wp_dropdown_categories('show_option_none=Select category'); ?>

    <script type="text/javascript"></script>



  • Dropdown without a Submit Button using JavaScript (2)

    使用JavaScript没有提交按钮的下拉列表 (2)

    In this example the echo parameter (echo=0) is used. A simple preg_replace inserts the JavaScript code. It even works without JavaScript (submit button is wrapped by noscript tags).

    这个例子使用了echo 参数 (echo=0)。一个简单的preg_replace插入了JavaScript代码。设置没有JavaScript也能够运行(提交按钮被noscript标签覆盖)。

    <li id="categories">
    	<h2><?php _e('Posts by Category'); ?></h2>
    	<form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    	$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
    	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    	echo $select;
    ?>
    	<noscript><input type="submit" value="View" /></noscript>
    	</form>
    </li>
    


    <li id="categories">
    	<h2><?php _e('Posts by Category'); ?></h2>
    	<form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
    	$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
    	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    	echo $select;
    ?>
    	<noscript><input type="submit" value="View" /></noscript>
    	</form>
    </li>
    


    Parameters

    参数

    show_option_all
    (string) Causes the HTML for the dropdown to allow you to select All of the categories.

    ;显示_所有_选项:(string)导致下拉列表的HTML,允许你选择所有的类别。

    show_option_none
    (string) Causes the HTML for the dropdown to allow you to select NONE of the categories.
    不_显示_选项
    (string)导致下拉列表的HTML,允许你不选择类别。
    orderby
    (string) Key to sort options by. Valid values:

    ;顺序:(string)给选项分类的关键词。有效的参数值:

    • 'ID' (Default)
    • 'name'
    • 'ID' (默认)
    • '名称'
    order
    (string) Sort order for options. Valid values:

    ;顺序: (string)选项的分类顺序。有效的参数值:

    • 'ASC' (Default)
    • 'DESC'


    • 'ASC' (默认的)
    • 'DESC'


    show_last_update
    (boolean) Sets whether to display the date of the last post in each category. Valid values:

    ;显示_最后的_更新:(boolean)设置是否在每个类别上显示最后一篇文章的日期。有效的参数值:

    • 1 (True)
    • 0 (False - Default)
    • 1 (正确的)
    • 0 (错误的 – 默认)
    show_count
    (boolean) Sets whether to display a count of posts in each category. Valid values:

    ;显示_数目:(boolean)设置是否显示每个类别中的文章的数目。有效的参数值:

    • 1 (True)
    • 0 (False - Default)
    • 1 (正确的)
    • 0 (错误的 – 默认)
    hide_empty
    (boolean) Sets whether to hide (not display) categories with no posts. Valid values:

    ;隐藏_空的: (boolean)设置是否隐藏(不显示)不包含有文章的类别。有效的参数值:

    • 1 (True - Default)
    • 0 (False)
    • 1 (正确的 – 默认)
    • 0 (错误的)
    child_of
    (integer) Only display categories that are children of the category identified by its ID. There is no default for this parameter.

    ;子:(整数)只显示类别ID识别的子类别。这个参数没有默认值。

    exclude
    (string) Comma separated list of category IDs to exclude. For example, 'exclude=4,12' means category IDs 4 and 12 will NOT be displayed/echoed or returned. Defaults to exclude nothing.

    ;移除:(string)用逗号分开要删除的类别的ID。例如,'删除=4,12',指的是类别IDs4和12不会被显示/echoed或者返回。默认不删除任何类别。

    echo
    (boolean) Display bookmarks (TRUE) or return them for use by PHP (FALSE). Defaults to TRUE.
    • 1 (True - default)
    echo
    (boolean)显示书签(正确的)或者返回书签供PHP使用(错误的)。默认真确的
    • 1 (正确的 – 默认)
    • 0 (False)
    • 0 (错误的)
    selected
    (integer) Category ID of the category to be 'selected' or presented in the display box. Defaults to no category selected.

    ;选择的:(整数)要被'挑选'或者显示在展示框中的类别的类别ID。默认不选择任何类别。

    hierarchical
    (boolean) Display categories in hierarchical fashion (child categories show indented). Defaults to FALSE.
    等级的
    (boolean)以等级级别的方式显示类别(子类别以嵌套的方式显示)。默认错误的
    • 1 (True)
    • 1 (正确的)
    • 0 (False - Default)
    • 0 (错误的 – 默认)
    name
    (string) Name assigned to the dropdown form. Defaults to 'cat'.
    姓名
    (string)给下拉列表指定的形式的名称。默认为'cat'。
    class
    (string) Class assinged to the dropdown form. Defaults to 'postform'.

    ;类别:(string)指定给下拉列表形式的类别。默认为'文章形式'。

    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 -所有的类别以平常格式(而不是缩进格式)显示(删除等级级别)。
    • 1 - Show only top level Categories
    • n - Value of n (some number) specifies the depth (or level) to descend in displaying Categories
    • 1 -只显示最高级别的类别
    • 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,

    模板:PHP Function Tag Footer


    相关的

    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 函数标签页底文字