見ている記事と同じカテゴリーの最新記事一覧を表示する方法

見ている記事と同じカテゴリーの最新記事一覧を表示する方法
<h3><?php the_category(' | '); ?>の最新記事</h3>
<?php
  $post_id = get_the_ID();
  foreach((get_the_category()) as $cat) {
    $cat_id = $cat->cat_ID ;
    break ;
  }
  query_posts(
    array(
      'cat' => $cat_id,
      'showposts' => 5,
      'post__not_in' => array($post_id)
    )
  );
  if(have_posts()) :
?>
<ul>
  <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  <?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>

参考サイト

TechMemo
[WordPress] 見ている記事と同じカテゴリーの最新記事一覧を表示する方法
http://techmemo.biz/wordpress/samecategory-newpost-list/