When you are developing themes in WordPress you will first see that the query returns 10 posts at a time, this is because there is an in-built pagination that will tell WordPress what chuck of posts to display. If you are on page one then WordPress will display the 10 latest posts, if you are on page 2 then WordPress will show the 11 - 20 latest posts. There are a few ways you can handle pagination in WordPress you can either display links at the bottom for the next and previous pages, or you can display a number of boxes for the different pages available.
WordPress has a function that will automatically create the previous and next links to the page, it will add the correct number of pagination on to the end of the links. To display the navigation links you need to use the function posts_nav_link( $sep, $prelabel, $nextlabel ).
posts_nav_link( $sep, $prelabel, $nextlabel );
This will add links to the page similar to this « Previous Page — Next Page » ## Pagination Links
If you would prefer links to a number of pages like this
Then you can do this with another WordPress function called paginate_links(). This function takes an array of all the parameters to pass into the paginate_links function, the options you have available to you are.
<?php $args = array(
'base' => '%_%',
'format' => '?page=%#%',
'total' => 1,
'current' => 0,
'show_all' => False,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => False,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
); ?>
The below function can be used to add pagination links to your theme, just add the following to your functions.php file and use the function pu_paging_nav() in your theme where you want to display the pagination links.
function pu_paging_nav()
{
global $wp_query;
$big = 999999999;
$pagination_links = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'mid_size' => 8,
'total' => $wp_query->max_num_pages
) );
echo $pagination_links;
}