WordPress: Template Tags/get the tags:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: == Description == Returns an array of objects, one object for each tag assigned to the post. This tag must be used within WordPress:The Loop. == Usage == This function does not dis...)
 
无编辑摘要
第1行: 第1行:
== Description ==
== Description ==
== 描述 ==


Returns an array of objects, one object for each tag assigned to the post. This tag must be used within [[WordPress:The Loop]].
Returns an array of objects, one object for each tag assigned to the post. This tag must be used within [[WordPress:The Loop]].
返回一组对象,每个递交给文章的标签分配一个对象。必须在[[WordPress:The Loop|The Loop]]内使用这个标签。


== Usage ==
== Usage ==
== 用法 ==


This function does not display anything; you should access the objects and then echo or otherwise use the desired member variables.
This function does not display anything; you should access the objects and then echo or otherwise use the desired member variables.
这个标签不显示任何内容;你应该访问objects,然后echo或者使用想要的变数。


The following example displays the tag name of each tag assigned to the post (this is like using [[WordPress:Template_Tags/the_tags|<tt>the_tags()</tt>]], but without linking each tag to the tag view, and using spaces instead of commas):
The following example displays the tag name of each tag assigned to the post (this is like using [[WordPress:Template_Tags/the_tags|<tt>the_tags()</tt>]], but without linking each tag to the tag view, and using spaces instead of commas):
下面的例子显示了递交给文章的每个标签的名称(这就如使用[[WordPress:Template_Tags/the_tags|<tt>the_tags()</tt>]],但是没有将每个标签链接到标签浏览,而且使用了空格,而不是逗号);
<pre><?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
?></pre>


<pre><?php
<pre><?php
第19行: 第38行:


== Examples ==
== Examples ==
== 例子 ==


===Show tag Images===
===Show tag Images===
===显示标签图像===


This outputs tag images named after the <tt>term_id</tt> with the <tt>alt</tt> attribute set to <tt>name</tt>. You can also use any of the other member variables instead.
This outputs tag images named after the <tt>term_id</tt> with the <tt>alt</tt> attribute set to <tt>name</tt>. You can also use any of the other member variables instead.
这使得标签图像以<tt>term_id</tt>命名 并且将<tt>alt</tt>属性设置为<tt>名称</tt>。你也可以使用其它的成员变数替代。
<pre><?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<img src="http://example.com/images/' . $tag->term_id . '.jpg"
alt="' . $tag->name . '" />';
}
}
?></pre>


<pre><?php
<pre><?php
第35行: 第70行:


===Show the First tag Name Only===
===Show the First tag Name Only===
===只显示第一个标签的名称===
<pre><?php
$tag = get_the_tags();
if ($tag) {
$tag = $tag[0]; echo $tag->name;
}
?></pre>


<pre><?php
<pre><?php
第44行: 第88行:


==Member Variables==
==Member Variables==
==Member变数==


;term_id :the tag id
;term_id :the tag id
第52行: 第98行:
;description :the tag description
;description :the tag description
;count :number of uses of this tag, total
;count :number of uses of this tag, total
;term_id :标签id
;名称 :标签名
;slug :有标签名产生的slug
;term_group :如果存在的话,是一组标签
;taxonomy :在这种情况下,应该总是 'post_tag'
;描述 :标签描述
;数目 :这个标签总共的使用次数


== Related ==
== Related ==
== 相关的==


{{Tag tag Tags}}
{{Tag tag Tags}}


{{Query String Tag Footer}}
{{Query String Tag Footer}}
{{标签 标签 标签}}
{{查询 字符串 标签页底文字}}

2008年7月10日 (四) 16:23的版本

Description

描述

Returns an array of objects, one object for each tag assigned to the post. This tag must be used within WordPress:The Loop.

返回一组对象,每个递交给文章的标签分配一个对象。必须在The Loop内使用这个标签。

Usage

用法

This function does not display anything; you should access the objects and then echo or otherwise use the desired member variables.

这个标签不显示任何内容;你应该访问objects,然后echo或者使用想要的变数。

The following example displays the tag name of each tag assigned to the post (this is like using the_tags(), but without linking each tag to the tag view, and using spaces instead of commas):

下面的例子显示了递交给文章的每个标签的名称(这就如使用the_tags(),但是没有将每个标签链接到标签浏览,而且使用了空格,而不是逗号);

<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' '; 
}
}
?>
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' '; 
}
}
?>

Examples

例子

Show tag Images

显示标签图像

This outputs tag images named after the term_id with the alt attribute set to name. You can also use any of the other member variables instead.

这使得标签图像以term_id命名 并且将alt属性设置为名称。你也可以使用其它的成员变数替代。

<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<img src="http://example.com/images/' . $tag->term_id . '.jpg" 
alt="' . $tag->name . '" />'; 
}
}
?>
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<img src="http://example.com/images/' . $tag->term_id . '.jpg" 
alt="' . $tag->name . '" />'; 
}
}
?>

Show the First tag Name Only

只显示第一个标签的名称

<?php
$tag = get_the_tags(); 
if ($tag) {
$tag = $tag[0]; echo $tag->name;
}
?>
<?php
$tag = get_the_tags(); 
if ($tag) {
$tag = $tag[0]; echo $tag->name;
}
?>

Member Variables

Member变数

term_id
the tag id
name
the tag name
slug
a slug generated from the tag name
term_group
the group of the tag, if any
taxonomy
should always be 'post_tag' for this case
description
the tag description
count
number of uses of this tag, total
term_id
标签id
名称
标签名
slug
有标签名产生的slug
term_group
如果存在的话,是一组标签
taxonomy
在这种情况下,应该总是 'post_tag'
描述
标签描述
数目
这个标签总共的使用次数

Related

相关的

模板:Tag tag Tags

模板:Query String Tag Footer

模板:标签 标签 标签

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