Here’s how I’d get the 20 (at most) most recent posts in the category.php
page:
<?php
$max_posts = 20;
$cat_ID = get_cat_ID ( single_cat_title( '', false ) );
$args = array(
'category' => $cat_ID,
'numberposts' => $max_posts,
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) {
setup_postdata( $post );
?>
<!-- add your HTML here, including the_title(), the_excerpt(), etc -->
<?php
}
?>
The code uses get_cat_ID()
and single_cat_title()
to get the ID of the current category. I’ve done some (very) minimal testing to make sure that it at least excludes posts that aren’t in the current category.