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('← Newer Entries') ?></span>
<span class="prev-page"><?php next_posts_link('Older Entries →') ?></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.
Don’t use
query_posts
in the template for simple modifications of the main query. Use thepre_get_posts
action instead to modify the query before it runs: