WordPress: previous_posts_link() and next_posts_link() with a custom query_posts()

How to get the previous and next links working on a custom WP query

Here’s the code that works within a plugin. The magic part here is the global $paged; 

 

<?php
global $paged;
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
query_posts('posts_per_page=5&paged=' . $paged);
?>

<?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( 'content', get_post_format() ); ?>
    
<?php endwhile; ?>



Leave a Reply

Your email address will not be published. Required fields are marked *