WordPress:Template Tags/the tags

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

Description

描述

First available with WordPress Version 2.3, this template tag displays a link to the tag or tags a post belongs to. If no tags are associated with the current entry, the associated category is displayed instead. This tag should be used within WordPress:The Loop.

这个标签首先出现在WordPress2.3版本中,这个模板标签显示一个链接,链接到文章属于的一个或者几个标签。如果没有哪个标签与当前文章有关,就会显示与当前文章相关的类别。应该在The Loop内使用这个标签。

Usage

用法

%%% <?php the_tags('before', 'separator', 'after'); ?> %%%

%%% <?php the_tags('before', 'separator', 'after'); ?> %%%

Examples

例子

Displays a list of the tags with a linebreak after it. %%% <?php the_tags('Tags:', ', ', '
'); ?> %%% 显示标签的一个列表,后面加上一个行分隔符。

Default Usage

默认用法

The default usage lists tags with each tag (if more than one) separated by a comma (,) and preceded with the default text Tags: .

默认用法,列出标签(如果多于一个标签的话),标签之间加上逗号,而且在默认文本标签: 的前面。

<p><?php the_tags(); ?></p>
<p><?php the_tags(); ?></p>
Tags: [[WordPress:#Examples|WordPress]], [[WordPress:#Examples|Computers]], [[WordPress:#Examples|Blogging]]


div style="border:1px solid blue; width:50%; padding:10px">Tags: [[WordPress:#Examples|WordPress]], [[WordPress:#Examples|电脑]], [[WordPress:#Examples|写博客]]


Separated by Arrow

用箭头分开

Displays links to tags with an arrow (>) separating the tags and preceded with the text Social tagging:

显示链接,链接到标签,用一个箭头(>)分开标签,而且箭头的前面有文本Social tagging:

<?php the_tags('Social tagging: ',' > '); ?>
<?php the_tags('Social tagging: ',' > '); ?>
Social tagging: [[WordPress:#Examples|WordPress]] > [[WordPress:#Examples|Computers]] > [[WordPress:#Examples|Blogging]]


Social tagging: [[WordPress:#Examples|WordPress]] > [[WordPress:#Examples|电脑]] > [[WordPress:#Examples|写博客]]


Separated by a Bullet

由一个Bullet分开

Displays links to tags with a bullet (•) separating the tags and preceded with the text Tagged with: and followed by a line break.

显示链接,链接到标签,用bullet (•)分开标签,而且bullet前面有文本Tagged with: ,后面由一个行分隔符。

%%%<?php

    the_tags('Tagged with: ',' &bull; ','
');

?>%%%

%%%<?php

    the_tags('Tagged with: ',' &bull; ','
');

?>%%%

Tagged with: [[WordPress:#Examples|WordPress]] • [[WordPress:#Examples|Computers]] • [[WordPress:#Examples|Blogging]]
Tagged with: [[WordPress:#Examples|WordPress]] • [[WordPress:#Examples|电脑]] • [[WordPress:#Examples|写博客]]

A List Example

A List例子

Displays a list of the tags as a real and simple (X)HTML list (<ul> / <ol> / <dl> ):

显示一列标签作为真正而且简单的(X)HTML列表(<ul> / <ol> / <dl> ):

%%%<?php

the_tags('

  • ','
  • ','

');

?>%%%

%%%<?php

the_tags('

  • ','
  • ','

');

?>%%%

  • [[WordPress:#Examples|WordPress]]
  • [[WordPress:#Examples|Computers]]
  • [[WordPress:#Examples|Blogging]]
  • [[WordPress:#Examples|WordPress]]
  • [[WordPress:#Examples|电脑]]
  • [[WordPress:#Examples|写博客]]

Integrating Categories and Tags

将类别和标签结合

If you have existing posts associated with categories, and have started adding tags to posts as well, you may want to show an integrated list of categories and tags beneath each post. For example, assume you have pre-existing categories called Culture and Media, and have added tags to a post "Arts" and "Painting". To simplify the reader's experience and keep things uncluttered, you may want to display these as if they were all tags:

你已经有了与类别有关的文章,而且开始向文章添加标签,你可能想要在每篇文章的下面显示类别和标签结合的一个列表。例如,假如你已经有了一个类别称为文化和媒体,而且已经添加了标签到称为"美术" 和"绘画"的文章中。要让读者感到更简单而且保持内容清晰明了,如果这些都是标签,你可能想要显示:

Tags: Culture, Media, Arts, Painting

标签: 文化,媒体,美术,绘画

This code will get you there, and will only render categories or tags if they're non-empty for the current post:

这个编码帮你解决了问题,而且对于当前文章如果这个代码是非空的,就会产生类别或者标签。

%%% Tags: <?php if (the_category(', ')) the_category(); ?> <?php if (get_the_tags()) the_tags(); ?> %%%

%%% 标签: <?php if (the_category(', ')) the_category(); ?> <?php if (get_the_tags()) the_tags(); ?> %%%

Parameters

参数

before
(string) Text to display before the actual tags are displayed. Defaults to Tags:

;之前: (string)真正的标签显示之前,显示的文本。默认为标签:

separator
(string) Text or character to display between each tag link. The default is a comma (,) between each tag.

;分隔符:(string)每个标签链接之间显示的文本或者字符。默认为每个标签之间有个逗号(,)。

after
(string) Text to display after the last tag. The default is to display nothing.

;之后:(string)最后一个标签之后显示的文本。默认为不显示任何内容。

Related

相关的

模板:Tag Tag Tags

模板:PHP Function Tag Footer

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

the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, previous_post_link, next_post_link, posts_nav_link, the_meta,

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