single.phpで現在のカテゴリーを取得し記事一覧を表示する
<?php foreach((get_the_category()) as $cat) { $cat_id = $cat->cat_ID ; break ; } $cat_now = 'cat=' . $cat_id. '&showposts=10'; query_posts($cat_now) ; if(have_posts()): while(have_posts()): the_post(); ?>
この場合、showpostsで10件表示するように指定している。
query_postsとループを使用しているので必ず最後は
<?php endwhile; endif; ?> <?php wp_reset_query() ?>
で終了させるのを忘れずに。
さらに現在見ているページを一覧表示させない為
<?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' => 10, 'post__not_in' => array($post_id) ) ); ?> <?php wp_reset_query(); ?>