How to add the home page and the last page

Source: Internet
Author: User
How to add the following pagination function to the homepage and last page without calculating the homepage and last page
How to add it? it's a bit confusing!
/*** Paging function ** @ param $ num total information * @ param $ curr_page current page * @ param $ perpage display number per page * @ param $ urlrule URL rule * @ param $ array the array to be passed, used to add an additional method * @ return paging */function pages ($ num, $ curr_page, $ perpage = 20, $ urlrule = '', $ array = array (), $ setpages = 10) {if (defined ('urlrule') & $ URLRULE = '') {$ urlrule = urlrule; $ array = $ GLOBALS ['url _ array'];} elseif ($ urlrule = '') {$ urlrule = url_par ('page = {$ page} ') ;}$ Multipage = ''; if ($ num> $ perpage) {$ page = $ setpages + 1; $ offset = ceil ($ setpages/2-1 ); $ pages = ceil ($ num/$ perpage); if (defined ('in _ admin ')&&! Defined ('Pages ') define ('Pages', $ PAGES); $ from = $ curr_page-$ offset; $ to = $ curr_page + $ offset; $ more = 0; if ($ page >=$ pages) {$ from = 2; $ to = $ pages-1;} else {if ($ from <= 1) {$ to = $ page-1; $ from = 2;} elseif ($ to >=$ pages) {$ from = $ pages-($ page-2 ); $ to = $ pages-1 ;}$ more = 1 ;}$ multipage. = ''. $ num. L ('page _ item '). ''; if ($ curr_page> 0) {$ multipage. = ''. L ('previous '). ''; // previous page function if ($ curr_page = 1) {$ mu Ltipage. = '1';} elseif ($ curr_page> 6 & $ more) {$ multipage. = '1 .. ';} else {$ multipage. = '1' ;}}for ($ I = $ from; $ I <=$ to; $ I ++) {if ($ I! = $ Curr_page) {$ multipage. = ''. $ I. '';} else {$ multipage. = ''. $ I. '';}} if ($ curr_page <$ pages) {if ($ curr_page <$ pages-5 & $ more) {$ multipage. = '.. '. $ pages. ''. L ('next '). ''; // next page function} else {$ multipage. = ''. $ pages. ''. L ('next '). '';}} elseif ($ curr_page ==$ pages) {$ multipage. = ''. $ pages. ''. L ('next '). '';} else {$ multipage. = ''. $ pages. ''. L ('next '). '';}} return $ multipage ;}


Reply to discussion (solution)

Do you still need to calculate the homepage and the last page? 1 is the homepage, and $ pages is the last page.

Do you still need to calculate the homepage and the last page? 1 is the homepage, and $ pages is the last page.


Maybe my expression is incorrect.
The main reason is that the homepage will not be represented. for example, if many Page codes are cyclically generated, the first one must be represented by an array.
In this example, I do not know how to use arrays to represent the first page number.

Of course, this is not just a question about what pages are displayed, but there are links, so we need to calculate them.

Isn't it written here?

if($curr_page==1) {elseif($curr_page==$pages) {



By the way, paste the page creation part in my paging component. please advise.
Function createPage (par) {var _ page ={}; // stores the running page information _ page. extendpage = par. extendpage? Par. extendpage: opt. extendpage; _ page. totalpage = par. totalpage; // compile the page var expbase = 4; _ page. page = parseInt (par. page); // used to solve the problem of weak type conversion failure in js if (isNaN (_ page. page) | isNaN (_ page. totalpage) {return; // paging error, no operation} opt. renderTo. empty (); opt. renderTo. append ('Current page number: '+ par. page + ''); // Insert create from the beginning from begin_page.pagenow = 1; // initialize the paging trace. If (_ page. page> = _ page. extendpage-1) {_ page. pagenow = 1; _ createPage (_ page, opt);} // Insert the middle page, that is, insert some intermediate pages between the previous page and the current page. start = _ page. pagenow + 1; _ page. end = _ page. page-_ page. extendpage-1; //// the middle of the free residual position, can insert data, use random or any other way to insert the middle page var tarr = []; for (var exppow = 1; _ page. start <_ page. end-_ mathexp (expbase, exppow); exppow ++) {_ page. pagenow = _ page. end-_ mathexp (expbase, exppow); tarr. push (_ page. pagenow); // _ createpage (par);} var tl = tarr. length; for (var I = 0; I
  
  

The home page and the last page are fixed. you can directly add the home page to the front of $ multipage, followed by the last page.

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.