Created
March 28, 2017 14:44
-
-
Save anonymous/1e76fb71e8d1c6de3622dab4db9ea5e2 to your computer and use it in GitHub Desktop.
アーカイブページでタームごとに記事一覧
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$taxonomy_name = 'タクソノミー名'; | |
$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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment