Custom Archive Index Page (with pagination)
Ok, so here’s something I had a little trouble with a couple of days ago. I just could not get it to work, although the answer was pretty obvious. I was working on creating a custom archive index page on a site and could not get the template the paginate. Here’s what i found to the quickest way to do it with query_posts():
-
query_posts(‘cat=3&paged=’ . get_query_var( ‘paged’ ));
-
-
if ( have_posts() ) : while ( have_posts() ) : the_post()
-
-
// do your thing here
-
-
endwhile;
-
-
endif;
-
-
wp_reset_query();
You have to make sure you pass the paged parameter to query_posts(), using get_query_var(‘page’). This is all I was forgetting. You could set this to something like ’3′, which would only display the posts that would normally show on page 3 of your paginated archive. Or you could make it dynamic by using get_query_var( ‘paged’ ). This will set it to whatever page you might be on at the time, with the URL containing something like /page/2.
And I always reset the query. Often times I am calling on the post ID in the sidebar, so not resetting the query will mess me up. It’s a good habit to get into when using query_posts().