- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
テンプレートタグ/get the tags
提供: WordPress Codex 日本語版
< テンプレートタグ
2008年3月30日 (日) 11:16時点におけるBono (トーク | 投稿記録)による版 (en:Template Tags/get_the_tags 2007年12月7日 (金) 18:21 NA3S 版)
目次
Description
Returns an array of objects, one object for each tag assigned to the post. This tag must be used within The Loop.
Usage
This function does not display anything; you should access the objects and then echo or otherwise use the desired member variables.
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):
<?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.
<?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; } ?>
Member Variables
- 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
Related