【问题标题】:SilverStripe PaginatedPages show custom summarySilverStripe PaginatedPages 显示自定义摘要
【发布时间】:2017-05-01 17:46:03
【问题描述】:

我在使用分页页面时遇到问题。在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]

【问题讨论】:

  • 您可以发布您正在使用的代码,以便我们了解一些上下文吗?
  • 嗨@UncleCheese,我已经用代码更新了我的问题。我希望这次我更清楚。感谢回复和帮助。

标签: php pagination silverstripe


【解决方案1】:

您可以使用$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 返回一个汇总分页,它限制当前页面周围显示的页面数量,以实现视觉平衡。它

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]。该数字应始终为偶数,因为每页的一半数显示在当前页的两侧。

【讨论】:

  • 啊非常好。谢谢@3dgoo
猜你喜欢
  • 1970-01-01
  • 2012-11-20
  • 1970-01-01
  • 1970-01-01
  • 2015-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多