SilverStripe PaginatedPages Shows Custom Resume
I am having problems using PaginatedPages. You can customize the summary in the docs .
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;
}
Breaking the page at 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 do not want it. If you have 20 pages of results, it will display everything and the result will be long and ugly.
I need the following:
[1] ... [9] [10] [11] [12] [13] ... [20]
source to share
You can use $PaginatedPages.PaginationSummary
to achieve this goal:
<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 the total pagination, which limits the number of pages displayed on the current page for visual balance. it
PaginationSummary
can take a parameter to control the number of pages to display around the current page. By default, will PaginationSummary
display 4 pages around the current page (2 pages before, 2 pages after, for example [1] ... [4] [5] [[6]] [7] [8] ... [25]
). The call PaginationSummary(6)
will result in 3 pages before and 3 pages after the current page. eg [1] ... [3] [4] [5] [[6]] [7] [8] [9] ... [25]
. The number must always be even, since half of the numbers of each page are displayed on either side of the current page.
source to share