WordPress: Template Tags/wp list pages:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
== 描述 == | == 描述 == | ||
模板标签,''' | 模板标签,'''wp_list_pages()''',显示了WordPres[[WordPress:Pages|网页]]的一个列表,作为一列链接。'''wp_list_pages()'''通过用来自定义[[WordPress:Customizing_Your_Sidebar|Sidebar]]或者 [[WordPress:Designing_Headers|Header]],但是也可能在其它的[[WordPress:Templates|模板]]中使用。 | ||
WordPress1.5版本以及更新的版本中拥有这个[[WordPress:Template Tags|模板标签]]。 | WordPress1.5版本以及更新的版本中拥有这个[[WordPress:Template Tags|模板标签]]。 | ||
== | == 用法== | ||
%%% <?php wp_list_pages('arguments'); ?> %%% | %%% <?php wp_list_pages('arguments'); ?> %%% | ||
== 例子== | == 例子== | ||
===默认用法=== | ===默认用法=== | ||
<pre> | <pre> | ||
第33行: | 第22行: | ||
'sort_column' => 'menu_order, post_title'); | 'sort_column' => 'menu_order, post_title'); | ||
</pre> | </pre> | ||
默认情况下,用法显示: | 默认情况下,用法显示: | ||
*显示了所有的网页和子网页(没有层级限制) | *显示了所有的网页和子网页(没有层级限制) | ||
*不显示创建的日期 | *不显示创建的日期 | ||
*不限制到任何网页的子网页 | *不限制到任何网页的子网页 | ||
*不删除任何网页 | *不删除任何网页 | ||
*网页的标题列为"网页" | *网页的标题列为"网页" | ||
*结果得到反映(显示) | *结果得到反映(显示) | ||
*文章不限制为某个作者的 | *文章不限制为某个作者的 | ||
*有网页顺序分类然后有网页标题分类。 | *有网页顺序分类然后有网页标题分类。 | ||
*以升序分类(不在上面的默认设置中显示) | *以升序分类(不在上面的默认设置中显示) | ||
*网页以层级嵌套的方式显示(不在上面的默认设置中显示) | *网页以层级嵌套的方式显示(不在上面的默认设置中显示) | ||
*包含所有的网页(不在上面的默认设置中显示) | *包含所有的网页(不在上面的默认设置中显示) | ||
*不限制为拥有特别的meta key/meta参数值的网页(不显示在上述的默认设置中) | *不限制为拥有特别的meta key/meta参数值的网页(不显示在上述的默认设置中) | ||
wp_list_pages(); | wp_list_pages(); | ||
=== 隐藏或者更改列表标头=== | === 隐藏或者更改列表标头=== | ||
''wp_list_pages''产生的网页("网页")列表的默认标题,可以通过向'''title_li''' 参数传递一个零或者空参数值,得到隐藏。下面的例子显示了列表上方没有标题文本。 | |||
<div style="padding: 1em; border: 1px dashed #2f6fab; | <div style="padding: 1em; border: 1px dashed #2f6fab; | ||
第117行: | 第63行: | ||
</tt> | </tt> | ||
</div> | </div> | ||
在下面的例子中,只有ID是9,5,23的网页包含在列表中而且标题文本被更改为"诗",标头形式为<tt><nowiki><h2></nowiki></tt>: | 在下面的例子中,只有ID是9,5,23的网页包含在列表中而且标题文本被更改为"诗",标头形式为<tt><nowiki><h2></nowiki></tt>: | ||
第143行: | 第75行: | ||
</tt> | </tt> | ||
</div> | </div> | ||
=== 根据网页顺序列出网页 === | === 根据网页顺序列出网页 === |
2008年7月13日 (日) 17:08的版本
描述
模板标签,wp_list_pages(),显示了WordPres网页的一个列表,作为一列链接。wp_list_pages()通过用来自定义Sidebar或者 Header,但是也可能在其它的模板中使用。
WordPress1.5版本以及更新的版本中拥有这个模板标签。
用法
%%% <?php wp_list_pages('arguments'); ?> %%%
例子
默认用法
$defaults = array( 'depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'), 'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order, post_title');
默认情况下,用法显示:
- 显示了所有的网页和子网页(没有层级限制)
- 不显示创建的日期
- 不限制到任何网页的子网页
- 不删除任何网页
- 网页的标题列为"网页"
- 结果得到反映(显示)
- 文章不限制为某个作者的
- 有网页顺序分类然后有网页标题分类。
- 以升序分类(不在上面的默认设置中显示)
- 网页以层级嵌套的方式显示(不在上面的默认设置中显示)
- 包含所有的网页(不在上面的默认设置中显示)
- 不限制为拥有特别的meta key/meta参数值的网页(不显示在上述的默认设置中)
wp_list_pages();
隐藏或者更改列表标头
wp_list_pages产生的网页("网页")列表的默认标题,可以通过向title_li 参数传递一个零或者空参数值,得到隐藏。下面的例子显示了列表上方没有标题文本。
<ul>
<?php
wp_list_pages('title_li='); ?>
</ul>
在下面的例子中,只有ID是9,5,23的网页包含在列表中而且标题文本被更改为"诗",标头形式为<h2>:
<ul>
<?php
wp_list_pages('include=5,9,23&title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>
根据网页顺序列出网页
The following example lists the Pages in the order defined by the Page Order settings for each Page in the Write > Page administrative panel.
下面的例子,根据写 > 网页 管理面板中设置的每个网页的排序来列出网页。
<ul>
<?php
wp_list_pages('sort_column=menu_order'); ?>
</ul>
<ul>
<?php
wp_list_pages('sort_column=menu_order'); ?>
</ul>
If you wanted to sort the list by Page Order and display the word "Prose" as the list heading (in h2 style) on a Sidebar, you could add the following code to the sidebar.php file:
如果你想要根据网页顺序给列表分类,而且在工具条上显示"散文"作为列表标题(以h2样式),你可以添加以下的代码到sidebar.php文件上:
<ul>
<?php
wp_list_pages('sort_column=menu_order&title_li=<h2>' . __('Prose') . '</h2>' ); ?>
</ul>
<ul>
<?php
wp_list_pages('sort_column=menu_order&title_li=<h2>' . __('Prose') . '</h2>' ); ?>
</ul>
Using the following piece of code, the Pages will display without heading and in Page Order:
使用下面的这些代码,网页会以网页顺序显示,而且还没有标题:
<ul>
<?php
wp_list_pages('sort_column=menu_order&title_li='); ?>
</ul>
<ul>
<?php
wp_list_pages('sort_column=menu_order&title_li='); ?>
</ul>
Sort Pages by Post Date
根据文章日期给网页分类
This example displays Pages sorted by (creation) date, and shows the date next to each Page list item.
这个例子显示了网页根据(创建)日期分类,而且在每个网页列表item的旁边显示了日期。
<ul>
<?php
wp_list_pages('sort_column=post_date&show_date=created'); ?>
</ul>
<ul>
<?php
wp_list_pages('sort_column=post_date&show_date=created'); ?>
</ul>
Exclude Pages from List
从列表中删除网页
Use the exclude parameter hide certain Pages from the list to be generated by wp_list_pages.
使用删除参数隐藏wp_list_pages产生的列表中的某个网页。
<ul>
<?php
wp_list_pages('exclude=17,38' ); ?>
</ul>
<ul>
<?php
wp_list_pages('exclude=17,38' ); ?>
</ul>
Include Pages in List
在列表中包含网页
To include only certain Pages in the list, for instance, Pages with ID numbers 35, 7, 26 and 13, use the include parameter. 在一个列表中只包含某个特别的网页,例如,ID数字为35,7,26和13的网页,使用包含参数。
<ul>
<?php
wp_list_pages('include=7,13,26,35&title_li=<h2>' . __('Pages') . '</h2>' ); ?>
</ul>
<ul>
<?php
wp_list_pages('包含=7,13,26,35&title_li=<h2>' . __('Pages') . '</h2>' ); ?>
</ul>
List Sub-Pages (versions prior to Wordpress 2.0.1)
列出子网页(Wordpress 2.0.1之前的版本)
Put this inside the the_post() section of the page.php template of your WordPress theme after the_content(), or put it in a copy of the page.php template that you use for pages that have sub-pages:
将这个放到the_内容()后的WordPress主题的page.php 模板的the_文章()部分的内部,或者将这个放到page.php模板的一个拷贝中,你为拥有子网页的网页使用这个page.php模板:
<ul>
<?php
global $id;
// teensy bit insane, sorry
$date_format = '<\b\r /><\s\p\a\n '.
'\s\t\y\l\e="\f\o\n\t-\s\i\z\e: \s\m\a\l\l\e\r">'.
'\l\a\s\t\m\o\d Y-n-j</\s\p\a\n>';
wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>
<ul>
<?php
global $id;
// teensy bit insane, sorry
$date_format = '<\b\r /><\s\p\a\n '.
'\s\t\y\l\e="\f\o\n\t-\s\i\z\e: \s\m\a\l\l\e\r">'.
'\l\a\s\t\m\o\d Y-n-j</\s\p\a\n>';
wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>
NOTE: This example does not work with Wordpress 2.0.1 or newer if placed in a page template because the global $id is not set. Use the following code
注:如果这个例子放到了一个网页模板中,在WordPress2.0.1或者更新的版本中不能够运行,因为没有设置全局$id。使用下面的代码
List Sub-Pages (Wordpress 2.0.1 or newer)
列出子网页 (Wordpress 2.0.1 或者更新的版本)
NOTE: Requires an HTML tag (either <ul> or <ol>) even if there are no subpages. Keep this in mind if you are using css to style the list.
注意:即使没有子网页,也需要一个HTML标签(<ul> 或者<ol>)。当你使用css设计列表的时候,要牢记这一点。
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
&date_format=$date_format'); ?>
</ul>
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
&date_format=$date_format'); ?>
</ul>
The following example will generate a list only if there are child (Pages that designate the current page as a Parent) for the current Page:
只有当前的网页拥有子网页的时候,下面的例子才会产生一个列表(子网页是指定当前网页为母网页的网页):
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
List subpages even if on a subpage
即使没有子网页,也列出子网页
The above examples will only show the children from the parent page, but not when actually on a child page. This code will show the child pages, and only the child pages, when on a parent or on one of the children.
上述的例子指示显示了来自于母网页的子网页,但是并不是真正地在一个子网页上,这个代码会显示子网页,而且只有子网页在母网页上或者在其中的一个子网页上时,参会显示。
- warning ** This code will not work if placed after a widget block in the sidebar.
- 警醒 ** 如果将这个代码放到一个工具条上的一个widget 块上时,这个代码就不会运行。
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
Markup and styling of page items
网页items的标记和样式
By default, wp_list_pages() generates a nested, unordered list of WordPress WordPress:Pages created with the Write > Page admin panel. You can remove the outermost item (li.pagenav) and list (ul) by setting the title_li parameter to an empty string.
默认情况下,wp_列表_网页()产生一个无序的,嵌套的WordPress网页,这个网页是用写 > 网页管理面板创建的。你可以通过将title_li参数设置为一个空字符串,可以移除最外面的item(li.pagenav)并且列出(ul)。
All list items (li) generated by wp_list_pages() are marked with the class page_item. When wp_list_pages() is called while displaying a Page, the list item for that Page is given the additional class current_page_item.
wp_列表_网页()产生的所有的列表items(li)都标记了class page_item。当显示网页的时候,调用了wp_list_pages(),关于那个网页的列表item会得到额外的class当前_网页_item。
<li class="pagenav"> Pages <ul> <li class="page_item current_page_parent"> [parent of the current page] <ul> <li class="page_item current_page_item"> [the current page] </li> </ul> </li> <li class="page_item"> [another page] </li> </ul> </li>
<li class="pagenav"> Pages <ul> <li class="page_item current_page_parent"> [parent of the current page] <ul> <li class="page_item current_page_item"> [the current page] </li> </ul> </li> <li class="page_item"> [another page] </li> </ul> </li>
They can be styled with CSS selectors: 这些可以用CSS 选择器设计:
.pagenav { ... } .page_item { ... } .current_page_item { ... } .current_page_parent { ... }
.pagenav { ... } .page_item { ... } .current_page_item { ... } .current_page_parent { ... }
Parameters
参数
- sort_column (string)
- Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page title.
- 分类_column (string)
- 以许多不同的方式给列出的网页分类。默认设置为根据网页标题的字母顺序分类。
- 'post_title' - Sort Pages alphabetically (by title) – default
- '文章_标题' -(根据标题)将网页按照字母顺序分类-默认
- 'menu_order' - Sort Pages by Page Order. N.B. Note the difference between Page Order and Page ID. The Page ID is a unique number assigned by WordPress to every post or page. The Page Order can be set by the user in the Write>Pages administrative panel. See the [[WordPress:#List Pages by Page Order|example]] below.
- 'menu_顺序' -根据网页顺序给网页分类。N.B. 注意网页顺序 和网页 ID之间的区别。网页ID是一个独特的数字,是由WordPress指定给每篇文章或者每个网页的。用户可以在写>网页管理面板上设置网页顺序。请看看下面的[[WordPress:#List Pages by Page Order|例子]]。
- 'post_date' - Sort by creation time.
- 'post_modified' - Sort by time last modified.
- 'ID' - Sort by numeric Page ID.
- 'post_author' - Sort by the Page author's numeric ID.
- 'post_name' - Sort alphabetically by Post slug.
- '文章_日期' - 根据创建时间分类。
- '更改的_文章' - 根据最后一次更改分类。
- 'ID' - 根据网页ID分类。
- '文章_作者' - 根据网页作者的 ID分类。
- '文章_名称' - 根据文章的slug,按字母顺序分类。
Note: The sort_column parameter can be used to sort the list of Pages by the descriptor of any field in the wp_post table of the WordPress database. Some useful examples are listed here.
注: sort_column参数可以用来给列出的网页分类,根据WordPress数据库的wp_文章 表格的任何栏中的描述符来给文章分类。这里列出了一些有用的例子。
- sort_order (string)
- Change the sort order of the list of Pages (either ascending or descending). The default is ascending. Valid values:
- 分类_顺序 (string)
- 更改列出的网页的分类顺序(升序的或者降序的)。默认为升序的,有效的参数值:
- 'asc' - Sort from lowest to highest (Default).
- 'desc' - Sort from highest to lowest.
- 'asc' -从最低到最高分类 (默认)。.
- 'desc' - 从最高到最低分类。
- exclude (string)
- Define a comma-separated list of Page IDs to be excluded from the list (example: 'exclude=3,7,31'). There is no default value. See the [[WordPress:#Exclude Pages from List|Exclude Pages from List]] example below.
- 删除 (string)
- 默认用逗号将需要从列表上删除的网页的ID分开(例如:'删除=3,7,31')。没有默认参数值。请看看下面的例子[[WordPress:#Exclude Pages from List|从列表中删除网页]]。
- include (string)
- Only include certain Pages in the list generated by wp_list_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. There is no default value. See the [[WordPress:#Include Pages in List|Include Pages in List]] example below.
- 包含 (string)
- 在wp_列表_网页产生的列表上只包含特别的网页。像删除,这个参数拥有一个用逗号分开的网页ID列表。没有默认参数值。请看看[[WordPress:#Include Pages in List|在一个列表中包含网页]]下面的例子。
- depth (integer)
- This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).
- 层级 (整数)
- 这个参数控制了wp_列表_网页产生的列表中可以包含多少层级的网页。默认值为0(显示所有的网页,包括子网页)。
- 0 - Pages and sub-pages displayed in hierarchical (indented) form (Default).
- 0 -以层级(嵌套)方式(默认)显示的网页和子网页。
- -1 - Pages in sub-pages displayed in flat (no indent) form.
- -1 -子网页中的网页以flat(非嵌套)的方式显示。
- 1 - Show only top level Pages
- 1 -只显示最高级别的网页
- 2 - Value of 2 (or greater) specifies the depth (or level) to descend in displaying Pages.
- 2 -值为2(或者更高)规定了显示网页时,可以下降的层次(或者层级)。
- child_of (integer)
- Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Defaults to 0 (displays all Pages).
- child_of (整数)
- 只显示一个单独网页的子网页;为一个网页使用ID作为参数值。默认为0(显示所有网页)。
- show_date (string)
- Display creation or last modified date next to each Page. The default value is the null value (do not display dates). Valid values:
- 显示_日期(string)
- 在每个网页的旁边显示创建或者最后更改的日期。默认值为零(不显示日期)。有效的参数值:
- '' - Display no date (Default).
- '' -不显示日期(默认)。
- 'modified' - Display the date last modified.
- '更改的' -显示最后更改的日期。
- 'xxx' - Any value other than modified displays the date (post_date) the Page was first created. See the [[WordPress:#Sort Pages by Post Date|example]] below.
- 'xxx' -除了modified的任何参数值显示了网页首次创建时的日期(文章_日期)。请看看下面的[[WordPress:#Sort Pages by Post Date|例子]]。
- date_format (string)
- Controls the format of the Page date set by the show_date parameter (example: "l, F j, Y"). This parameter defaults to the date format configured in your WordPress options. See WordPress:Formatting Date and Time and the date format page on the php web site.
- 数据_格式 (string):控制了显示_日期参数设置的网页日期格式(例如:"l, F j, Y")。这个参数默认日期格式为配置在WordPress上的选项。请看看日期和时间格式和php 网站上的日期格式网页
- title_li (string)
- Set the text and style of the Page list's heading. Defaults to '__('Pages')', which displays "Pages" (the __('') is used for localization purposes). If passed a null or empty value (''), no heading is displayed, and the list will not be wrapped with <ul>, </ul> tags. See the example for [[WordPress:#Hiding or Changing the List Heading|Headings]].
- title_li (string)
- 设置网页列表的标头的文本和样式。默认为'__('网页')',显示了"网页"(为本地化目的使用__(''))。如果传递了一个零或者空的参数值,(''),不显示任何标题,而且列表也不会外包上<ul>, </ul>标签。请看看关于[[WordPress:#Hiding or Changing the List Heading|标头]]的例子。
- echo (boolean)
- Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 1 (display the generated list items). Valid values:
- 1 (true) - default
- 0 (false)
- echo (boolean)
- Toggles链接产生的列表的显示或者返回链接作为HTML文本字符串,用于PHP。默认值为1(显示产生的列表item)。有效的参数值:
- 1 (正确的) - 默认
- 0 (错误的)
- hierarchical
- (boolean) Display sub-Pages in an indented manner below their parent or list the Pages inline. The default is true (display sub-Pages indented below the parent list item). Valid values:
;层级的:(boolean)在母网页下,以嵌套的方式显示子网页,或者列出网页inline。默认为真的(显示嵌套在母列表item下面的子网页)。有效的参数值:
- 1 (true) - default
- 0 (false)
- 1 (正确的) - 默认
- 0 (错误的)
- meta_key
- (string) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field).
- meta_key
- (string)只包含拥有这个自定义Field Key的网页(和meta_value field用在一起)。
- meta_value
- (string) Only include the Pages that have this Custom Field Value (use in conjuntion with the meta_key field).
- meta_value
- (string) 只包含拥有这个自定义Field Key参数值的网页(和meta_key field用在一起)。
Related
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.