WordPress:Template Tags/get the tag list

来自站长百科
Fludlen讨论 | 贡献2008年7月10日 (四) 16:24的版本
跳转至: 导航、​ 搜索

Description

描述

Generates a HTML string of the tags associated with the current post. The name of each tag will be linked to the relevant 'tag' page. You can tell the function to put a string before and after all the tags, and in between each tag. This tag must be used inside 'The Loop'.

创建与当前文章相关的标签的HTML字符串。每个标签的名称会链接到相关的'标签'网页。你可以命令函数在所有的标签前后放置一个字符串,而且在每个标签之间也放置一个字符串。必须在'The Loop'内使用这个标签。

Usage

用法

This function does not display anything - if you want to put it straight onto the page, you should use echo (get_the_tag_list()). Alternatively, you can assign it to a variable for further use by using $foo = get_the_tag_list().

这个函数不显示任何内容 – 如果你想要直接地将这个函数放到网页上,你应该使用echo (get_the_tag_list())。另外,你可以通过使用$foo = get_the_tag_list(),将这个函数递交给一个变数,以便以后使用。

The variables are all optional, and should be placed in the order 'before', 'separator', 'after'. You can use HTML inside each of the fields.

变数都是可选择的,而且应该以'前', '分隔符', '后'的顺序排列。你可以在每个区内使用HTML。

Example

例子

A Basic Example

一个基本的例子

This outputs the list of tags inside a paragraph, with tags separated by commas.

这在一个段落中产生了一列标签,标签是用逗号分开的。

<?php
echo get_the_tag_list('<p>Tags: ',', ','</p>');
?>
<?php
echo get_the_tag_list('<p>Tags: ',', ','</p>');
?>

This would return something like. 这会返回:

<p>
Tags: 
<a href="tag1">Tag 1</a>, 
<a href="tag2">Tag 2</a>, ... 
</p>
<p>
标签: 
<a href="tag1">Tag 1</a>, 
<a href="tag2">Tag 2</a>, ... 
</p>

A Slightly More Complex Example

A Slightly More Complex Example

一个稍微复杂的例子

This checks if the post has any tags, and if there are, outputs them to a standard unordered list.

这个例子检查文章是否含有任何标签,如果文章含有标签,将标签放到一个标准的无序列表上。

<?php
if(get_the_tag_list()) {
 get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
}
?>
<?php
if(get_the_tag_list()) {
 get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
}
?>

This will return something in the form: 这会返回以这个形式出现的内容;

<ul>
<li><a href="tag1">Tag 1</a></li>
<li><a href="tag2">Tag 2</a></li>
 ... 
</ul>
<ul>
<li><a href="tag1">Tag 1</a></li>
<li><a href="tag2">Tag 2</a></li>
 ... 
</ul>

You can add classes and styles with CSS, as necessary./ 如果需要的话,你可以添加CSS的class和样式。/

模板:Tag Tag Tags

模板:PHP Function Tag Footer

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.

模板:标签标签 标签

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.