- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/get the term list
指定されたタクソノミー(カスタム分類)に関して、投稿に付けられたタームの HTML 文字列を返します。 タームの文字列は、そのタームのアーカイブページへリンクします。
使い方
<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
パラメータ
- $id
- (整数) (必須) 投稿 ID
- 初期値: なし
- $taxonomy
- (文字列) (必須) タクソノミーの名前
- 初期値: なし
- $before
- (文字列) (オプション) 前に入れる文字列
- 初期値: 空文字列
- $sep
- (文字列) (オプション) タームを区切る文字列
- 初期値: 空文字列
- $after
- (文字列) (オプション) 後に続く文字列
- 初期値: 空文字列
戻り値
- (文字列)
- タームの HTML 文字列
例
基本的な例
ループ内で使用すると、下記の例は、特定の投稿の people カスタム分類のタームを出力します。
<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' ); ?>
以下のような出力になります。
People: <a href="person1">Person 1</a>, <a href="person2">Person 2</a>, ...
HTML のリストを返す
ループ内で使用すると、下記の例は、特定の投稿の styles カスタム分類のタームを (x)html のリストで出力します。
echo '<ul class="styles">'; echo get_the_term_list( $post->ID, 'styles', '<li>', ',</li><li>', '</li>' ); echo '</ul>';
以下のような出力になります。
<ul class="styles"> <li><a href="person1">Style 1,</a></li> <li><a href="person2">Style 2,</a></li> </ul>
変更履歴
- 2.5.0 にて導入されました。
ソースファイル
get_the_term_list() は wp-includes/category-template.php
にあります。
関連項目
タームタグ: is_term(), term_exists(), get_objects_in_term(), get_term(), get_term_by(), get_term_children(), get_term_link(), get_terms(), get_the_terms(), get_the_term_list(), has_term(), sanitize_term(), the_terms(), get_object_taxonomies() is_object_in_taxonomy() the_taxonomies() wp_get_object_terms(), wp_set_object_terms(), wp_get_post_terms(), wp_set_post_terms(), wp_delete_object_term_relationships()
最新英語版: WordPress Codex » Function Reference/get the term list (最新版との差分)