ループ内で
親で分岐と同じコードを使い表示
<h2><div class="title1">
<?php //シングルでターム名を全部取得表示
if ($terms = get_the_terms($post->ID, 'cate_jirei')) {
foreach ( $terms as $term ) {
echo esc_html($term->name);
}
}
?>
<?php //シングルDDD分岐 $term_p に タームの親のたーむIDが入る 2つのコードで使用
//ループでホームページカテゴリか分岐
//これは親を選択せずに小カテゴリのみ選択していった場合にも有効な親のIDで分岐する方法 但し、複数の親の子は未対応
//& 親を選択しないカテゴリの場合の親情報を取得 これはすぐしたのコード
//ループ内でタームの親で分岐準備 逆さになる場合があるから下記分岐
$term = array_pop(get_the_terms($post->ID, 'cate_jirei')); //array_popで配列の最後を取り出す
$term_p = $term->parent; //子か確かめる準備
if ( $term_p == 0 ) //取り出したのが親の場合
{
$term = array_shift(get_the_terms($post->ID,'cate_jirei')); //array_shiftで先頭にある配列を取り出す
}
$term_p = $term->parent; //親のID取得
?>
<?php //ここからシングルのタイトル用のコード
$ddterm = get_term($term_p , 'cate_jirei'); //
echo $ddterm->name;
?>
実績
</div></h2>