SilverStripe PaginatedPages 显示自定义摘要

SilverStripe PaginatedPages show custom summary

我在使用分页页面时遇到了问题。在 docs 中,可以自定义摘要。

这是我的代码:

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;
}

模板页面底部分页:

<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>

此代码重现:

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

我不想要这个。如果有 20 页的结果,它会显示所有结果,结果又长又丑。

我想要以下内容:

[1] ... [9] [10] [11] [12] [13] ... [20]

您可以使用 $PaginatedPages.PaginationSummary 来实现:

<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 一种汇总分页,它限制了当前页面周围显示的页面数量以实现视觉平衡。它

PaginationSummary可以带一个参数来控制当前页周围显示的页数。默认情况下 PaginationSummary 将在当前页面周围显示 4 页(前 2 页,后 2 页。例如 [1] ... [4] [5] [[6]] [7] [8] ... [25])。调用 PaginationSummary(6) 将导致当前页面之前的 3 页和之后的 3 页。例如 [1] ... [3] [4] [5] [[6]] [7] [8] [9] ... [25]。数量应该始终是偶数,因为每页的一半数量显示在当前页面的两侧。