Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
SilverStripe PaginatedPages show custom summary

I am have trouble using the PaginatedPages. In the docs, it's possible to customize the summary.

There is my code :

public function PaginatedPages($n = 10) {
    $list = Page::get()->sort(array('Date' => DESC));
    $Pages = new PaginatedList($list, $this->request);
    if ($_GET['results'] != "") {
        $n = $_GET['results'];
    }
    $Pages->setPageLength($n);
    return $Pages;
}

The pagination in the bottom of the template page :

<div id="PaginatedPages">
    <% if $PaginatedPages.MoreThanOnePage %>
        <% if $PaginatedPages.NotFirstPage %>
            <a class="prev" href="$PaginatedPages.PrevLink"><</a>
        <% end_if %>
        <% loop $PaginatedPages.Pages %>
            <% if $CurrentBool %>
                <a class="current">$PageNum</a>
            <% else %>
                <% if $Link %>
                    <a href="$Link">$PageNum</a>
                <% else %>
                    ...
                <% end_if %>
            <% end_if %>
            <% end_loop %>
        <% if $PaginatedPages.NotLastPage %>
            <a class="next" href="$PaginatedPages.NextLink">></a>
        <% end_if %>
    <% end_if %>
</div>

This code reproduces:

[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20]

I don't want this. If a have 20 pages of results, it will show all and the result is to long and ugly.

I want the following:

[1] ... [9] [10] [11] [12] [13] ... [20]
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use $PaginatedPages.PaginationSummary to achieve this:

<div id="PaginatedPages">
    <% if $PaginatedPages.MoreThanOnePage %>
        <% if $PaginatedPages.NotFirstPage %>
            <a class="prev" href="$PaginatedPages.PrevLink"><</a>
        <% end_if %>
        <% loop $PaginatedPages.PaginationSummary %>
            <% if $CurrentBool %>
                <a class="current">$PageNum</a>
            <% else %>
                <% if $Link %>
                    <a href="$Link">$PageNum</a>
                <% else %>
                    ...
                <% end_if %>
            <% end_if %>
            <% end_loop %>
        <% if $PaginatedPages.NotLastPage %>
            <a class="next" href="$PaginatedPages.NextLink">></a>
        <% end_if %>
    <% end_if %>
</div>

PaginationSummary returns a summarised pagination which limits the number of pages shown around the current page for visually balanced. It

PaginationSummary can take a parameter to control the number of pages to display around the current page. By default PaginationSummary will show 4 pages around the current page (2 pages before, 2 pages after. eg [1] ... [4] [5] [[6]] [7] [8] ... [25]). Calling PaginationSummary(6) would result in 3 pages before and 3 pages after the current page. eg [1] ... [3] [4] [5] [[6]] [7] [8] [9] ... [25]. The number should always be even, as half the number of each pages are displayed on either side of the current one.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!