Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1e76fb71e8d1c6de3622dab4db9ea5e2 to your computer and use it in GitHub Desktop.
Save anonymous/1e76fb71e8d1c6de3622dab4db9ea5e2 to your computer and use it in GitHub Desktop.
アーカイブページでタームごとに記事一覧
<?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