[WP]WordPressのタームをリンクなしで表示する方法
スポンサード
スポンサード
WordPressでタームの情報を取得する際、get_the_term_list
は投稿に付けられたタームの情報をリンク付きで返してくれますが、リンクなしの文字列が欲しい場合はget_the_terms
を使います。
リンクなしでターム情報を出力する
get_the_terms
は記事のターム情報を配列で返しますので、foreach文を使います。1 2 3 4 5 6 7 8 9 10 | <?php $terms = get_the_terms( get_the_ID(), 'タクソノミー' ); if ( !empty($terms) ) : if ( !is_wp_error($terms) ) : ?> <ul> <?php foreach( $terms as $term ) : ?> <li><?php echo $term->name; ?></li> <?php endforeach; ?> </ul> <?php endif; endif; ?> |
スポンサード
コメント