WordPress prev Next Page no plugin paging function

Source: Internet
Author: User
Tags php tutorial prev

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.