Title: 親子タームのパンくずリスト
Last modified: 2019年11月27日

---

# 親子タームのパンくずリスト

 *  [totete](https://ja.wordpress.org/support/users/totete/)
 * (@totete)
 * [6年、 11ヶ月前](https://ja.wordpress.org/support/topic/%e8%a6%aa%e5%ad%90%e3%82%bf%e3%83%bc%e3%83%a0%e3%81%ae%e3%83%91%e3%83%b3%e3%81%8f%e3%81%9a%e3%83%aa%e3%82%b9%e3%83%88/)
 * 親子タームのパンくずリストを作っています。
    子タームの記事一覧を表示してる場合、
   トップ＞ブログ＞親ターム（リンク付き）＞子ターム（リンク無し）。 シングルページ
   では、トップ＞ブログ＞親カテゴリー（リンク付き）＞子ターム（リンク付き）＞記事
   名。 にしたいと思っています。 以下のコードでは理想の形にはなっています。
 *     ```
       <ol>
       <li><a href="<?php echo bloginfo('url'); ?>">ホーム</a></li>
       <?php global $post;
       if(is_single() || is_tax() || is_date()):?>
       <li><a href="<?php echo bloginfo('url'); ?>/blog"><?php echo esc_html(get_post_type_object(get_post_type())->label); ?></a></li>
       <?php else: ?>
       <li><?php echo esc_html(get_post_type_object(get_post_type())->labels->singular_name ); ?></li>
       <?php endif; ?>
   
       <?php if(is_tax()):?>
       <?php
       $terms = wp_get_object_terms( $post->ID, 'blog_category');
       $term_id = $terms[0]->term_id;
       $ancestors = get_ancestors( $term_id, 'blog_category' );
       $reversed_ancestors = array_reverse($ancestors); 
       foreach($reversed_ancestors as $ancestor){
       echo '<li><a href="'. get_term_link($ancestor) .'">'. get_term($ancestor)->name .'</a></li>';
       }
       ?>
       <li><?php echo $wp_query ->get_queried_object() ->name;?></li>
       <?php endif; ?>
   
       <?php if(is_single()): ?>		
       <?php
       $terms = wp_get_object_terms( $post->ID, 'blog_category');
       $term_id = $terms[0]->term_id;
       $ancestors = get_ancestors( $term_id, 'blog_category' );
       $reversed_ancestors = array_reverse($ancestors); 
       foreach($reversed_ancestors as $ancestor){
       echo '<li><a href="'. get_term_link($ancestor) .'">'. get_term($ancestor)->name .'</a></li>';
       }
       ?>
       <?php
       $terms = get_the_terms($post->ID, 'blog_category');
       foreach($terms as $term) {
       echo '<li><a href="'.get_term_link($term->slug, $term->taxonomy).'">'.$terms[0]->name.'</a></li>';
       }
       ?>
       <li><?php the_title(''); ?></li>
       <?php endif; ?>
       </ol>
       ```
   
 * ですが、以下のコードで親子カテゴリーの一覧を取得できると思ったのですが、親ターム
   しか表示されません。どう変更したら、自動で親ターム＞子ターム＞孫タームのように
   取得できるでしょうか？
 *     ```
       <?php
       $terms = wp_get_object_terms( $post->ID, 'blog_category');
       $term_id = $terms[0]->term_id;
       $ancestors = get_ancestors( $term_id, 'blog_category' );
       $reversed_ancestors = array_reverse($ancestors); 
       foreach($reversed_ancestors as $ancestor){
       echo '<li><a href="'. get_term_link($ancestor) .'">'. get_term($ancestor)->name .'</a></li>';
       }
       ?>
       ```
   
    -  このトピックは[totete](https://ja.wordpress.org/support/users/totete/)が6
      年、 11ヶ月前に変更しました。
    -  このトピックは[totete](https://ja.wordpress.org/support/users/totete/)が6
      年、 11ヶ月前に変更しました。

 トピック「親子タームのパンくずリスト」には新たに返信することはできません。

## タグ

 * [タクソノミー](https://ja.wordpress.org/support/topic-tag/%e3%82%bf%e3%82%af%e3%82%bd%e3%83%8e%e3%83%9f%e3%83%bc/)
 * [ターム](https://ja.wordpress.org/support/topic-tag/%e3%82%bf%e3%83%bc%e3%83%a0/)
 * [パンくずリスト](https://ja.wordpress.org/support/topic-tag/%e3%83%91%e3%83%b3%e3%81%8f%e3%81%9a%e3%83%aa%e3%82%b9%e3%83%88/)

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0件の返信
 * 1人の参加者
 * 最後の返信者: [totete](https://ja.wordpress.org/support/users/totete/)
 * 最後の活動: [6年、 11ヶ月前](https://ja.wordpress.org/support/topic/%e8%a6%aa%e5%ad%90%e3%82%bf%e3%83%bc%e3%83%a0%e3%81%ae%e3%83%91%e3%83%b3%e3%81%8f%e3%81%9a%e3%83%aa%e3%82%b9%e3%83%88/)
 * 状態: 未解決

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
