WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
<?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>
        <?php the_excerpt(); ?>
<?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<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>

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.

share|improve this question
It's probably because query_posts runs a new query instead of just editing the main one. try editing that out and see if that helps – Manny Fleurmond Mar 25 '13 at 1:05
Thank you. I didn't realize that WordPress doesn't "combine" the values like jQuery does. – railgun Mar 25 '13 at 1:09
up vote 8 down vote accepted

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' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.