Skip to content

Instantly share code, notes, and snippets.

Created Mar 28, 2017
Embed
What would you like to do?
アーカイブページでタームごとに記事一覧
<?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