PHPCMS Custom Paging

Source: Internet
Author: User

Find the paging function in global.func.php
function pages ($num, $curr _page, $perpage =, $urlrule = ", $array = Array (), $setpages = 10) {...}
Make a copy, change a name, say,
function Test_pages ($num, $curr _page, $perpage =, $urlrule = ", $array = Array (), $setpages = 10) {...}

1 /**2 * Test the paging function3  *4 * Total @param $num information5 * @param $curr _page Current page6 * @param $perpage display per page7 * @param $urlrule URL rules8 * @param $array The array to be passed to add additional methods9 * @return PaginationTen  */ One functionTest_pages ($num,$curr _page,$perpage= 20,$urlrule= ",$array=Array(),$setpages= 10) { A     if(defined(' Urlrule ') &&$urlrule= = "') { -         $urlrule=Urlrule; -         $array=$GLOBALS[' Url_array ']; the}ElseIf($urlrule= = "') { -         $urlrule= Url_par (' page={$page} '); -     } -     $multipage= ' '; +     if($num>$perpage) { -         $page=$setpages+1; +         $offset=Ceil($setpages/2-1); A         $pages=Ceil($num/$perpage); at         if(defined(' In_admin ') &&!defined(' PAGES '))Define(' PAGES ',$pages); -         $from=$curr _page-$offset; -         $to=$curr _page+$offset; -         $more= 0; -         if($page>=$pages) { -             $from= 2; in             $to=$pages-1; -}Else { to             if($from<= 1) { +                 $to=$page-1; -                 $from= 2; the}ElseIf($to>=$pages) { *                 $from=$pages-($page-2); $                 $to=$pages-1;Panax Notoginseng             } -             $more= 1; the}

From here on the Internet is the core part of the page, can not be changed down is some of the pagination style, oneself in accordance with the form to put, this is I write a relatively simple page style behind the figure
And here I am more lazy without language packs, interested friends can put all the Chinese into the language pack
Variable interpretation $pages = = Total pages $curr _page = = Current Page pageurl ($urlrule, page n, $array) function is used to generate the URL, $urlrule and $array default on the line

 $multipage. = ' Total: <font color= ' #ff0000 ' > '.$pages.‘ </font> page, <font color= "#ff0000" > ".$num.‘ </font> article, '; $multipage. = ' Current page: <font color= ' #ff0000 ' > '.$curr _page. ' </font> '; if($curr _page>0){                    if($curr _page==1){                        $multipage. = ' <a href= '. Pageurl ($urlrule,$curr _page+1,$array) .‘" > next Page </a>| '; $multipage. = ' <a href= '. Pageurl ($urlrule,$pages,$array) .‘" > last page </a>| '; }                    Else if($curr _page<$pages){                        $multipage. = ' <a href= '. Pageurl ($urlrule, 1,$array) .‘" > Home </a>| '; $multipage. = ' <a href= '. Pageurl ($urlrule,$curr _page-1,$array) .‘" > previous Page </a>| '; $multipage. = ' <a href= '. Pageurl ($urlrule,$curr _page+1,$array) .‘" > next Page </a>| '; $multipage. = ' <a href= '. Pageurl ($urlrule,$pages,$array) .‘" > last page </a>| '; }                    Else if($curr _page==$pages){                        $multipage. = ' <a href= '. Pageurl ($urlrule, 1,$array) .‘" > Home </a>| '; $multipage. = ' <a href= '. Pageurl ($urlrule,$curr _page-1,$array) .‘" > previous Page </a>| '; }                }//Total: <font color= "#ff0000" >5</font> page, <font color= "#ff0000" >199</font> article,//Current page:< Font color= "#ff0000" > 2 </font>//<a href= "?classid=1&amp; Topage=1 "> Home </a>|//<a href="?classid=1&amp; Topage=1 "> Prev </a>|//<a href="?classid=1&amp; Topage=3 "> Next </a>|//<a href="?classid=1&amp;              Topage=5 "> Last page </a>|     }    return $multipage;}

Home time

Middle Page

Last page

After you finish writing this,
Found in lib/classes/template_cache.class.php
$str. = ' $pages = Pages ($ '. $op. ' _total, $page, $pagesize, $urlrule);
Add a line below
$str. = ' $test _pages = test_pages ($ '. $op. ' _total, $page, $pagesize, $urlrule);

Then the foreground call was originally written {$pages} now write {$test _pages}.

Some of the tutorials on the web, I didn't use it. Comment here for

Of course, if the use of the process, found that the SQL paging does not work, and then in the
$str. = ' $r = $get _db->sql_query ("'. $sql. '"); $s = $get _db->fetch_next (); $pages =pages ($s [\ ' count\ '], $page, $pagesize, $urlrule); ';
Add this code:

$str. = ' $r = $get _db->sql_query ("'. $sql. '"); $s = $get _db->fetch_next (); $pages _my=pages_my ($s [\ ' count\ '], $page, $pagesize, $urlrule); ';

Phpcms a custom page-out

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.