全タクソノミーの最新記事を表示する
2013-04-25
前回の、全カテゴリー~に続き、全タクソノミーの一覧表示です。
参考サイトでは、すごく分かりやすい説明があります。
<?php $taxonomy_name = 'news_type'; $taxonomys = get_terms($taxonomy_name); if(!is_wp_error($taxonomys) && count($taxonomys)): foreach($taxonomys as $taxonomy): $tax_posts = get_posts(array('post_type' => get_post_type(), 'taxonomy' => $taxonomy_name, 'term' => $taxonomy->slug ) ); if($tax_posts): ?> <div class="category"> <h2><?php echo esc_html($taxonomy->name); ?></span></h2> <ul> <?php foreach($tax_posts as $tax_post): ?> <li><a href="<?php echo get_permalink($tax_post->ID); ?>"><?php echo esc_html($tax_post->post_title); ?></a></li> <?php endforeach; ?> </ul> </div> <?php endif; endforeach; endif; ?>