Paging List Limit

I am working on updating the paging system of sites, and I came across something simple, I can not solve. I'm trying to show pages (1 2 3 4 5) at the same time, and when the user gets to page 5, the list will change to something like (4 5 6 7 8). How can I do this using cfloop? Here is an example of my code:

<cfloop from="1" to="#totalPages#" index="i">
<cfoutput><a class="paging" href="?start=#(i*25)-24#">#i#</a></cfoutput> 
</cfloop>

At the moment, it shows pages 1 - 54 all at once. Any tips?

+3
source share
3 answers

Here is my code

<cfset curPage = Int(start / 25) + 1>

<cfloop from="1" to="#totalPages#" index="i">
  <cfif i is curPage>
    <div class="page current">#i#</div>
  <cfelse>
    <cfif totalPages lte 5 or i is 1 or i is totalPages or (i gt curPage - 3 and i lt curPage + 3) or ((curPage is 1 or curPage is 2) and i lt 6) >
      <div class="page"><a href="?start=#(i*25)-24#">#i#</a></div>
    <cfelse>
      <cfif i is 2 or i is totalPages - 1>
        <div class="more">...</div>
      </cfif>
    </cfif>
  </cfif>
</cfloop>

What this code does is it shows the first 5 pages, then the ellipsis, then the last page. As you view it, it will always show a link to the first and last page, plus 2 pages before and after the current page.

: 1 Page 1 . 10 enter image description here

, , . ( , , )

+4

, . , . , . :

http://www.dopefly.com/projects/pagination/

, . , #pagination.getRenderedHTML()#. , , , .

+2

:

<cfloop from="#url.startpage#" to="#url.startpage+4#" index="i">
  <cfif i LE totalpages>
    <cfoutput><a class="paging" href="?start=#(i*25)-24#">#i#</a></cfoutput> 
  </cfif>
</cfloop>

Of course, you will need to add a β€œstart page” to your URL and manipulate it accordingly. So your first link will be startpage = 1, but your last will be startpage = 4 (if I understood your question correctly).

0
source

All Articles