Add Pagination To Your WordPress Without Any Plugin

You could say that today’s another “No Plugin Day” as I once again feature another useful WordPress trick that will help you customize your site sans the plugins. This tutorial was shared by Chunlinsay of WooShift and it shows you how to add pagination links to your WordPress.

ScreenHunter 72 Aug. 23 08.30 Add Pagination To Your WordPress Without Any PluginAgain, as with most WordPress hacks and tricks, this one won’t require you to do much to customize your blog. All it takes is for you to add a snippet of code into your functions.php file.

Copy and paste the following code below in to your functions.php file:

function get_pagenavi () { 
 global $wp_query, $wp_rewrite; 
 $wp_query -> query_vars['paged'] > 1 ? $current = $wp_query -> query_vars['paged'] : $current = 1; 
 $pagination = array(
 'base' => @add_query_arg('page', '%#%'), 
 'format' => '',
 'total' => $wp_query -> max_num_pages,
 'current' => $current,
 'mid_size' => 5,
 'prev_text' => '?',
 'next_text' => '?'
 ); 
 if ($wp_rewrite -> using_permalinks()) {
 $pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
 } 
 if (!empty($wp_query -> query_vars['s'])) {
 $pagination['add_args'] = array('s' => get_query_var('s'));
 } 
 echo paginate_links($pagination); 
}

Next, place this is into any theme templates where you want the pagination links to be displayed (ex. index.php, category.php, etc.):

<div><?php get_pagenavi(); ?></div>

And that’s basically it! Congratulations. You now have pagination links.

Incoming search terms for the article:

Related Posts

Inspirational Photo Retouches By Cristian Girotto

Create Your Own Sticker Design Via Photoshop

Twitter Cards PHP 1.1

Selfoss 2.4 – A Nice and Simple Alternative To Google Reader

No comments