3

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]
3dgoo
  • 15,716
  • 6
  • 46
  • 58
StefGuev
  • 639
  • 4
  • 16

1 Answers1

6

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.

3dgoo
  • 15,716
  • 6
  • 46
  • 58