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 am using a Specialized Page Template to display list of posts. I am using the following code for that:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'paged' => $paged
$all_posts = get_posts($args); 

<?php foreach ( $all_posts as $post ) : setup_postdata( $post );  ?>
/* the loop */
<?php endforeach; ?>

Now I want to put "Newer Posts" and "Older Posts" links below it. next_posts_link() and previous_posts_link() prints nothing here. How can I add these two links on this page?

share|improve this question
up vote 0 down vote accepted

You can achieve this using WP_Query as shown in the following code. To know more information on this visit this page.

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( 'posts_per_page=5&paged=' . $paged ); 

if ( $the_query->have_posts() ) :

    // the loop
    while ( $the_query->have_posts() ) : $the_query->the_post(); 

next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );

// clean up after our query
endif;  ?>
share|improve this answer
It's working with this way. Thank you. – Debiprasad Aug 23 '13 at 7:46

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.