Tutorials

How to Add Pagination to WordPress

Pagination is a must have feature of a blog, which helps in easy navigation and faster page load time. If your blog has got 50 posts and all of them are loaded at the same time on single page, it would load very slowly and will definitely increase the bounce rate. So, pagination helps distribute the content in multiple pages.

If you are running your blog on wordpress then there are various plugins to implement pagination. Apart from plugins, there are manual ways of doint it through code:

Numeric Pagination

<?php
function numeric_pagination() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'type' => 'list'
));
}
}
?>
view raw wp-pagination.php hosted with ❤ by GitHub

Add above code to functions.php file of your theme. Now, call the above function numeric_pagination() after posts loop in the index.php file. Know more about paginate_links on codex.

Simple Pagination

If you don’t want to use numeric pagination, then simply call the_posts_navigation() function after posts loop. Know more about the_posts_navigation on codex.

Plugins

There are many plugins available in wordpress.org to implement pagination. If you don’t know coding then i would advice you to use a plugin.

 

Leave a Reply

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