get_the_tags – WordPress*リファレンス

オブジェクト、ポストに割り当てられた各タグあたり1個のオブジェクトの配列を返します。 Loopの中でこのタグを使用しなければなりません。

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

get_the_tagsのタグ使用方法

この機能は何も表示しません; 物にアクセスします。次に、あなたは、必要なメンバー変数を反映するべきであるか、またはそうでなければ、使用するべきです。

以下の例はポストに割り当てられたそれぞれのタグのタグ名を表示します(the_tags()を使用しますが、各タグをタグ視点にリンクして、コンマの代わりに空間は使用しないで、これはあります):

原文 ⇒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 . ' ';
}
} ?>

get_the_tagsの例

タグイメージを表示

これは命名するalt属性セットでterm_idにちなんで名付けられたタグイメージを出力します。 また、あなたは代わりに他のメンバー変数のいずれも使用することができます。

原文 ⇒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="<a href="http://example.com/images/'" class="external free" title="http://example.com/images/'" rel="nofollow">http://example.com/images/'</a> . $tag->term_id . '.jpg"
alt="' . $tag->name . '" />';
}
}
?>

最初のタグの名前だけ表示する方法

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

Member Variables

before

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

separator

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

after

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

使用例

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

Template:Tag tag Tags

使用例

関連テンプレートタグ

the_tags,get_the_tags,get_the_tag_list,single_tag_title,is_tag,get_tag_link,wp_tag_cloud,wp_generate_tag_cloud


HOME » テンプレートタグ » タグ tags » get_the_tags – WordPress*リファレンス