The Complete Script
<?php // Init a variable to store the values of the original WP Query $temp_query = $wp_query; // Init a variable for a new custom WP Query. $args = array ( 'paged' => $paged, // the rest of your custom query goes here ); // Instantiate a new query $wp_query = new WP_Query($args); if (have_posts()) : ?> /* loop begins */ <?php while (have_posts()) : the_post(); ?> <!-- do stuff ... --> <?php endwhile; ?> <div class="navigation clearfix"> <div class="alignright"><?php next_posts_link('Additional Supporters »') ?></div> <div class="alignleft"><?php previous_posts_link('« Additional Supporters') ?></div> </div> <?php // Restore the $wp_query back to its original state $wp_query = $temp_query; endif; /* loop ends */ ?>
To use, you can copy/past this in your page template after the first instance of the Loop.
Notes and Resources
- Any parameter accepted by the Query is optional, but the paged parameter (
'paged' => paged) is required.
- You don’t have to set the number of posts to be shown in the custom query (
'posts_per_page' => 5). This can be set in the Reading settings under Settings in your WP Dashboard (“Settings → Reading → Blog pages show at most”). Just be aware that this is a site‐wide setting and will affect any Page that shows Posts.
- More information on the WordPress WP_Query Class can be found here in the Codex.
- More information on the WordPress Loop can be found here in the Codex.
- More information on using multiple Loops on a single page can be found here in the Codex.
Easy customization is one of the major strengths of utilizing WordPress. The ability to show multiple, varied posts on one page further extends WordPress into a more robust content management system. By using this modified custom query and Loop, we are now able to paginate any query we need.
I hope this comes in handy for someone when developing a theme or just for learning purposes. It was designed specifically to work in this instance, but it should work in most WP installs. I’m always open to feedback, so if you see areas of improvement or something I‐ve overlooked, just let me know!