タームごとの記事一覧を表示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php $taxonomy_name = 'タクソノミースラッグ'; $taxonomys = get_terms($taxonomy_name); if(!is_wp_error($taxonomys) && count($taxonomys)): foreach($taxonomys as $taxonomy): $args = array( 'post_type' => get_post_type(), 'tax_query' => array( array( 'taxonomy' => $taxonomy_name, 'field' => 'slug', 'terms' => $taxonomy->slug, ), ), ); $the_query = new WP_Query( $args ); ?> <?php if ($the_query->have_posts()): ?> <?php echo esc_html($taxonomy->name); ?> <ul> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <li><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php endif;?> <?php wp_reset_postdata();?> <?php endforeach;?> <?php endif;?> |
コメント