Why doesn’t /2013/01/ properly return January’s archives in archive.php?

I’ve figured out how to implement pagination into WordPress archives, etc.., but the content isn’t being returned correctly. Instead of /2013/01/ returning January 2013’s archives, it instead returns the latest posts. My code is below:

<h2><?php echo wp_title('',TRUE,'right'); ?></h2>
<ul>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts('showposts=5&paged='.$paged); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <div class="clearfix"><li>
        <h4><a rel="bookmark" href="<?php the_permalink(); ?>">
            <?php echo the_post_thumbnail('full'); ?>
            <span><?php the_title(); ?></span>
        </a></h4>
        <?php the_excerpt(); ?>
    </li></div>
<?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</ul>
<h4 class="page-nav clearfix">
    <span class="next-page"><?php previous_posts_link('&larr; Newer Entries') ?></span>
    <span class="prev-page"><?php next_posts_link('Older Entries &rarr;') ?></span>
</h4>

I’m sure that there is a simple solution, but I haven’t had any luck on Google or in the WordPress documentation. Help would be appreciated.

Related posts

Leave a Reply

1 comment

  1. Don’t use query_posts in the template for simple modifications of the main query. Use the pre_get_posts action instead to modify the query before it runs:

    function wpa_date_posts_per_page( $query ) {
        if ( !is_admin() && $query->is_date() && $query->is_main_query() ) {
            $query->set( 'posts_per_page', 5 );
        }
    }
    add_action( 'pre_get_posts', 'wpa_date_posts_per_page' );