- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
テンプレートタグ/get the tags
このページ「テンプレートタグ/get the tags」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
目次
説明
Returns an array of objects, one object for each tag assigned to the post. This tag must be used within The Loop.
使い方
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 . ' '; } } ?>
用例
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
変更履歴
- 2.3 : 新規テンプレートタグ
関連
タグ:
get_tag(),
get_tag_link(),
get_tags(),
get_the_tag_list(),
get_the_tags(),
is_tag(),
the_tags(),
single_tag_title(),
tag_description(),
wp_generate_tag_cloud(),
wp_tag_cloud()
最新英語版: WordPress Codex » Template Tags/get_the_tags (最新版との差分)