I'm using the index.php file and editing this so that it displays two articles at a time. I'm using query_posts( $query_string . '&posts_per_page=2' ); before the main loop and it's displaying what I want correctly.

How can I have a page navigation at the bottom?

migrated from stackoverflow.com Aug 25 '11 at 16:02

This question came from our site for professional and enthusiast programmers.

  • 3
    do you have any reason not to use dashboard -> settings -> reading -> Blog pages show at most [] posts – Michael Aug 25 '11 at 16:18
  • are you asking for wordpress functions such as next_posts_link(), previous_posts_link(), or posts_nav_link() or pagination plugins? – Michael Aug 25 '11 at 18:16

As in the comments, it's not clear why you can't use the options: dashboard -> settings -> reading -> Blog pages show at most [] posts

However, if it is necessary that this be done via altering the query (say to target only specific pages, or archives) then this should really be done on pre_get_post:

For instance to change the post's per page for any archive for a term in the 'my-tax' taxonomy:

function wpse26898_change_per_post( $query ){
    if( $query->is_main_query() && is_tax('my-tax') ){

query_posts alters the main loop and messes up pagination.

Use new WP_Query to show your first 2 posts before the main loop.


$args = array(
    'posts_per_page' => 2,

$myquery = new WP_Query( $args );

        while ( $myquery->have_posts() ) : $myquery->the_post(); 

//Do stuff



//Run main loop

For custom queries you need to enable paging by including $paged in your query parameters.

$paged is a global that gets set/updated whenever you're within a query context. WordPress looks at the URL structure /page/x in the url to determine the page number, x being the number. It is then used by the standard paging functions eg. previous_posts_link() and next_posts_link() until it is overwritten or reset using wp_reset_query().

// new query that respects $paged
query_posts( $query_string . '&posts_per_page=2&paged=' . $paged );

if ( have_posts() ) :

    while ( have_posts() ) : the_post();

        get_template_part( 'post' );


    // pagination links to show next 2 or previous 2 posts


// return to the original URL query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy