How to create a wordpress query_post with pagination
The wordpress query_post function has its advantages and disadvantage. One of the major advantage of the wordpress query_post function is that it will allow the user to specify what sort of information is pulled from the database onto the requested page. However one of the major disadvantages is lack of pagination while using the query_post function. Many times a page is not able to paginate to another page if the user is using a query_post function to recall the information.
However by using the code below that can all change.
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
‘paged’=>$paged, //Pulls the paged function into the query
‘posts_per_page’=>5, //Limits the amount of posts on each page
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!– Display Content –>
<!– Display Pagination –>
<?php endwhile; endif;
Therefore if there are ten posts on this page it will show the first five and paginate to the next five on the following page. The user is also able to add other parameters to the query_posts below the ‘posts_per_page’ parameter. Click here for more information on various query_post parameters.