親タームのアーカイブでは、
以下のように子タームを取得し、URL付きの子タームをリスト表示しました。
php
1<div class="sortBox"> 2<ul class="sortNav"> 3<li class="btnall">ALL</li> 4<?php 5$term_id = get_queried_object_id(); // タームIDの取得 6$taxonomy_name = 'ling_cat2'; 7$termchildren = get_term_children( $term_id, $taxonomy_name ); 8foreach ( $termchildren as $child ) :?> 9<?php $term = get_term_by( 'id', $child, $taxonomy_name );?> 10<li><a href="<?php echo home_url(); ?>/archives/ling_cat2/<?php echo $term->slug; ?>"><?php echo $term->name;?></a></li> 11<?php endforeach; ?> 12</ul> 13</div>
※以下、2020/01/28に追記いたしました。
その後、再度調べて以下のようなコードで、カテゴリーではうまく表示することができました。
php
1<?php 2/* 現在のカテゴリ-の取得 */ 3$cat_now = get_the_category(); 4$cat_now = $cat_now[0]; 5/*親カテゴリーのID取得*/ 6$parent_id = $cat_now->category_parent; 7?> 8<?php wp_list_categories("title_li=&child_of=$parent_id"); ?>
しかし、タームになるとうまく表示できません。
再度ご教示いただけると嬉しいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー