Home > Wordpress > Tutorial > Custom WordPress pagination without plugins
Custom WordPress pagination without plugins

Custom WordPress pagination without plugins

There are some useful Pagination Plugin for WordPress But WP-PageNavi is definitely one of the most popular WordPress plugins and in fact, it is very useful. WordPress had a built-in function called paginate_links(), which can be used to create to paginate your blog without using any plugin?

Here is the code to display Pagination in your blog.

global $wp_query; // global WP Quesry variable
$total = $wp_query->max_num_pages; // get the total number of pages
// Display Pagination if have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether you're using pretty permalinks
     $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/';
     echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => $format,
          'current' => $current_page,
          'total' => $total,
          'mid_size' => 4,
          'type' => 'list'
     ));
}

Source  Smashing Magazine

About Nadeem Ashraf

Add Comment Register



Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>