都道府県別3階層のカテゴリーをタームごとにループしたい
-
西日本、東日本の2ページに分けて表示する都道府県別店舗紹介ページで
カスタム投稿のカテゴリは
・西日本
ー兵庫県
ーー神戸市
ーー加古川市
ー京都府・東日本
ー東京都
ー神奈川県など、2階層のものと3階層のものがあり、
■兵庫県
ー神戸市
・店舗名
・店舗名
ー加古川市
・店舗名
・店舗名
■京都府
・店舗名
・店舗名のように、3階層の場合はさらにループさせたいのですが
if($wp_query->queried_object->parent == 0) : $term_id = $wp_query->queried_object->term_id; $taxonomy_name = $wp_query->queried_object->taxonomy; $termchildren = get_term_children( $term_id, $taxonomy_name ); foreach ( $termchildren as $child ) : $taxs[] = $child; endforeach; foreach( $taxs as $tax_slug) : //ターム名取得 $term_info = get_term_by( 'id', $tax_slug, $taxonomy_name ); $args = array( 'taxonomy' => 'saloncategory', 'nopaging' => true, 'tax_query' => array( array( 'taxonomy' => $taxonomy_name, 'field' => 'id', 'terms' => array( $tax_slug ), ) ), ); query_posts($args); if ( have_posts() ) : ?> <h2><?php echo $term_info->name; ?></h2> <ul> <?php while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php endif;?> <?php wp_reset_query(); ?> <?php endforeach; ?><!-- $taxs --> <?php endif; ?><!-- End of If parent category -->
このコードだと3階層もつ場合、2階層目と3階層目が同じ階層の扱いになって
■兵庫県
・店舗名
・店舗名
■神戸市
・店舗名
・店舗名となってしまいます。
3階層名がある場合さらにループさせるにはどうすればいいでしょうか。
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「都道府県別3階層のカテゴリーをタームごとにループしたい」には新たに返信することはできません。