Provide two, one is provided by Willin, one is today I provide, in fact, are simple changes, but can be used to meet the needs of different applications.
The first can be customized display WordPress display previous page next page, and Count pages and middle pages
The code is as follows |
Copy Code |
if (!function_exists (' Pagenavi ')) { function Pagenavi ($p = 5) {//2 pages before and after the current page if (Is_singular ()) return; Articles and inserts not Global $WP _query, $paged; $max _page = $wp _query->max_num_pages; if ($max _page = = 1) return; Only one page. if (empty ($paged)) $paged = 1; Echo ' <span class= "pages" >page: '. $paged. ' of '. $max _page. ' </span> '; Show pages if ($paged > 1) p_link ($paged-1, ' prev ', ' «previous ');//* If the current page is greater than 1 display the previous page link * * if ($paged > $p + 1) p_link (1, ' front page '); if ($paged > $p + 2) echo ' ... '; for ($i = $paged-$p; $i <= $paged + $p; $i + +) {//middle page if ($i > 0 && $i <= $max _page) $i = = $paged? Print "<span class= ' page-numbers current ' >{$i}</span>": P_link ($i); } if ($paged < $max _page-$p-1) echo ' ... '; if ($paged < $max _page-$p) p_link ($max _page, ' last page '); if ($paged < $max _page) P_link ($paged + 1, ' next page ', ' next» ');/* If the current page is not the last page to display the next link/* } function P_link ($i, $title = ', $linktype = ') { if ($title = = ") $title =" {$i} page "; if ($linktype = =) {$linktext = $i;} else {$linktext = $linktype;} echo "<a class= ' page-numbers ' href= '", Esc_html (Get_pagenum_link ($i)), "' Title= ' {$title} ' >{$linktext}</a& Gt "; } } |
The second one is today's main share, showing only the next page of the previous page, customizable style
The code is as follows |
Copy Code |
if (!function_exists (' Pagenavi ')) { function Pagenavi () { if (Is_singular ()) return; Articles and inserts not Global $WP _query, $paged; $max _page = $wp _query->max_num_pages; if (empty ($paged)) $paged = 1; if ($paged > 1) P_LINKP ($paged-1, ' prev ');//* If the current page is greater than 1 display the previous page link * * if ($paged = = 1) p_linkp1 ($paged);/* Display a gray link if the current page is equal to 1 * *
if ($paged < $max _page) p_linkn ($paged + 1, ' next page ');/* If the current page is not the last page to display the next link * * if ($paged = = $max _page) p_linkp0 ($paged)//* If current page equals last page show Gray link * * } function P_linkp ($i, $title = ', $linktype = ') { echo "<div class= ' pre-page page ' ><a href= '", Esc_html (Get_pagenum_link ($i)), "' Title= ' {$title} ' >{$linkte Xt}</a></div> "; } function P_linkn ($i, $title = ', $linktype = ') { echo "<div class= ' next-page page ' ><a href= '", Esc_html (Get_pagenum_link ($i)), "' Title= ' {$title} ' >{$linkt Ext}</a></div> "; } function P_linkp0 () { echo "<div class= ' pre-page page nav0 ' ></a></div>"; } function P_linkp1 () { echo "<div class= ' pre-page page nav1 ' ></a></div>"; } } |
As for the display effect, the first can see my blog paging effect, the second environment run down on the line, if you think this complex we can go to the PHP tutorial channel to refer to more paging program OH.