Easy WordPress Pagination Function

0
1904
views


Easy WordPress Pagination Function : We all remember the Wp-navigation plugin that we had to install in order to get the posts and pages pagination with page number. Now there is a very good and easy to use function that will give you the possibility to get a very nice pages and posts Pagination navigation.

If you didn’t use this function yet, so open your Functions.php file from your theme and add this code :

function wp_corenavi () { 
global $ wp_query, $ wp_rewrite; 
$ Pages =''; 
$ Max = $ wp_query -> max_num_pages; 
if (! $ current = get_query_var ('paged')) $ current = 1; 
$ A ['base'] = str_replace (999999999, '% #%', get_pagenum_link (999999999)); 
$ A ['total'] = $ max; 
$ A ['current'] = $ current; 

$ Total = 1 / / 1 - show the text "Page N of N", 0 - do not display 
$ A ['mid_size'] = 3; / / show how many links on the left and right of the current 
$ A ['end_size'] = 1 / / how many references show the beginning and end of the 
$ A ['prev_text'] = '«'; / / link text" Previous Page " 
$ A ['next_text'] = '»'; / / link text" Next Page " 

if ($ max> 1) echo '
'; 
if ($ total == 1 && $ max> 1) $ pages = ' Page'. $ current. ' of '. $ max.'  '. " r  n"; 
echo $ pages. paginate_links ($ a); 
if ($ max> 1) echo ''; 
}

To dis­play the nav­i­ga­tion in the right place, insert the following code in your theme:

<?php if (function_exists ('wp_corenavi')) wp_corenavi ();?>

The HTML code as a result of the function out­put is as follows:

<div class = "navigation"> 
<span class = "pages"> Page 7 of 27 </ span> 
<a class = 'prev page-numbers' href = 'http://wordpress31/page/6/'> «Previous </ a> 
<a class = 'page-numbers' href = 'http://wordpress31/page/1/'> 1 </ a> 
<span class = 'page-numbers dots'> ... </ span> 
<a class = 'page-numbers' href = 'http://wordpress31/page/4/'> 4 </ a> 
<a class = 'page-numbers' href = 'http://wordpress31/page/5/'> 5 </ a> 
<a class = 'page-numbers' href = 'http://wordpress31/page/6/'> 6 </ a> 
<span class = 'page-numbers current'> 7 </ span> 
<a class = 'page-numbers' href = 'http://wordpress31/page/8/'> 8 </ a> 
<a class = 'page-numbers' href = 'http://wordpress31/page/9/'> 9 </ a> 
<a class = 'page-numbers' href = 'http://wordpress31/page/10/'> 10 </ a> 
<span class = 'page-numbers dots'> ... </ span> 
<a class = 'page-numbers' href = 'http://wordpress31/page/27/'> 27 </ a> 
<a class = 'next page-numbers' href = 'http://wordpress31/page/8/'> Next »</ a> 
</div>

As you can see, there are all the nec­es­sary CSS classes that can be used to design every ele­ment nav­i­ga­tion.

Goodluck


LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.