WordPressにて以下のような名前でカスタム投稿を作成しています。
カスタム投稿名 works
タクソノミー名 works-cat
ターム名 bath , wash , kitchen, total
今回やりたいことは、single.phpにて、
1つの記事で、複数のタームにチェックが入っている場合、
1つのタームだけを取得します。
それが「bath」または「wash」のタームだった場合に
php
1<li class='cat'> 2 <a href=/works-cat/bath-wash/" ><div class='botton'>お風呂・洗面施工事例一覧に戻る</div></a> 3</li>
それ以外のカテゴリだった場合に
php
1<li class='cat'> 2 <a href="/works-cat/(タームのslug)/" ><div class='botton'>(ターム名)施工事例一覧に戻る</div></a> 3</li>
と、わけて表示したいです。
現在は以下のように書いて、1つのカテゴリだけを取得しているのですが
bathとwashの場合だけ分岐したい場合はどのように書けばよいのでしょうか。
php
1 <?php 2 //get terms 3 $terms = get_the_terms( get_the_ID(), 'works-cat' ); 4 $termtag = "<li class='cat'>"; 5 if ( !empty($terms) ) { 6 if ( !is_wp_error( $terms ) ) { 7 foreach( $terms as $term ) { 8 $linkurl = get_term_link($term->term_id , 'works-cat'); 9 $termtag .= "<a href=\"$linkurl\" ><div class='botton'>{$term->name}施工事例一覧に戻る</div></a>"; 10 break; 11 } 12 $termtag .= "</li>"; 13 echo $termtag; 14 } 15 } 16 ?>
わかりにくく申し訳ありません。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/29 06:23
2017/06/29 07:39
2017/07/05 00:02 編集