etc-plugins/etc_pagination

Textpattern CMS 分页插件

安装: 43

依赖项: 0

建议者: 0

安全性: 0

星标: 4

关注者: 5

分支: 3

开放问题: 1

类型:textpattern-plugin

0.5.0 2018-09-14 09:15 UTC

This package is auto-updated.

Last update: 2024-09-11 05:28:48 UTC


README

下载 | Packagist

此Textpattern插件在列表中创建分页导航栏。它具有丰富的属性,您可以自定义它直到满意为止!它可以单独用于<txp:article /><txp:article_custom />分页,但也可以通过etc_query帮助分页任何列表。

请在此插件的GitHub项目问题页面报告错误和问题。

注意,此插件创建的列表旨在由您使用CSS进行样式设计。

安装

使用Composer

$ composer require etc-plugins/etc_pagination:*

或从GitHub项目页面下载插件的最新版本,将代码粘贴到Textpattern插件管理面板中,安装并启用插件。访问论坛线程获取更多信息或报告插件的成败。

要求

  • Textpattern 4.5.0或更高版本。

标签

etc_pagination标签

<txp:etc_pagination />

etc_pagination标签是一个个或容器标签,用于渲染分页小部件的HTML结构。

如果用作容器,必须指定为成对的开启和关闭标签,如下所示

<txp:etc_pagination>
    ...contained statements...
</txp:etc_pagination>

属性

  • atts="value"
    应用于wraptag属性值的额外属性。
  • break="value"
    值是一个HTML元素,指定时无括号(例如,break="li"),用于分隔列表项。
  • class="class name"
    应用于wraptag属性值的HTML class
  • current="text"
    当前选项卡上的活动文本。
  • delimiter="value"
    general,current链接对中使用作分隔符的字符串。默认:,(逗号)。
  • first="text"
    允许您更改“第一”链接中的文本。
  • gap="text"
    一个或两个由分隔符分隔的符号,表明在当前可见选项卡之前或之后还有更多选项卡。默认:
  • html_id="id"
    分配给wraptag属性值的HTML id属性。
  • last="text"
    允许您更改“最后一页”链接中的文本。
  • link="text"
    允许您更改页面选项卡标题中的文本。如果给出了两个由分隔符分隔的字符串,则第一个将用于general页面,第二个将用于current页面。默认:{*},其中{*}将被适当的选项卡编号替换,请参阅下面的“替换”部分。
  • mask="value"
    如果设置,整个输出将通过用相应字符串替换以下模式{links}{first}{last}{prev}{next}{<+}(前面的间隔)和{+>}(后面的间隔)来构建。默认:未设置。
  • next="text"
    允许您更改“下一页”链接中的文本。
  • offset="number"
    页面编号偏移量。默认:0
  • 页面="编号"
    一个整数,用作默认页面(通常是1)。
  • pages="值"
    总页数,或一个范围start..end,或一个以分隔符分隔的page[::title]项的列表。在分页<txp:article />标签时不需要(默认值)。
  • pgcounter="值"
    用于导航的URL参数。在分页<txp:article />标签时不需要。默认:pg
  • prev="文本"
    允许您更改“上一个”链接中的文本。
  • query="a&b=c"
    一个用&分隔的GET参数列表,要在root中取消设置/修改。
  • range="数字"
    要显示的最大左/右相邻页数(包括间隔)。如果为负(默认值),将显示所有页面。插件尝试避免像1 … 3 4这样的“无意义”间隔,并调整输出,使显示的标签数量为2*range+1
  • reversenumberorder="数字"
    使您能够反转标签中的数字。将值设置为0(默认值)将显示1,2,3,...,将值设置为1将反转链接数字,2将反转它们的href,3将反转数字和href。
  • root="URL"
    用作导航基础的URL,默认为当前页面URL。
  • scale="1"
    用作“间隔”链接网格的整数。
  • wraptag="元素"
    要包装(标记)的HTML元素,指定时无需括号(例如,wraptag="ul")。

替换

如果您对默认的<a>链接不满意,请使用<etc_pagination />作为容器来构建自己的链接。在etc_pagination内部可用以下替换令牌

  • {$}
    绝对页码。
  • {#}
    显示的页码。
  • {*}
    页面标题。
  • {current}
    current属性提供的文本,仅在当前标签上启用。
  • {href}
    页面URL。
  • {link}
    link属性提供的文本,在需要时由firstprev等替换。
  • {pages}
    总页数。
  • {rel}
    页面关系(nextprev)。

例如,以下(容器标签)将生成一个<select>分页列表

<txp:etc_pagination link="Page {*}" current="selected" wraptag="select" atts='name="pg"'>
    <option value="{*}" {current}>{link}</option>
</txp:etc_pagination

示例

示例 1
<txp:etc_pagination range="2" prev="Previous" next="Next"  wraptag="ul" break="li" />

此示例输出,如果有十页且我们处于第三页,如下所示

<ul>
    <li>
        <a href="https://example.com/blog/?pg=2" rel="prev">Previous</a>
    </li>
    <li>
        <a href="https://example.com/blog/">1</a>
    </li>
    <li>
        <a href="https://example.com/blog/?pg=2">2</a>
    </li>
    <li>
        <span data-rel="current">3</span>
    </li>
    <li>
        <span data-rel="gap">…</span>
    </li>
    <li>
        <a href="https://example.com/blog/?pg=10">10</a>
    </li>
    <li>
        <a href="https://example.com/blog/?pg=4" rel="next">Next</a>
    </li>
</ul>

链接到firstprevcurrentnextlastgap页面的<a><span>标签将获得相应的reldata-rel属性值。

示例 2
<txp:etc_pagination range="0">
    <p>Page {*} of {pages}</p>
</txp:etc_pagination>

此示例输出,如果有八页且我们处于第六页,如下所示

<p>Page 6 of 8</p>
示例 3
<txp:etc_pagination wraptag="nav" class="paginator" range="3" atts='aria-label="Blog navigation"'
    prev='<a class="prev" rel="prev" href="https://example.com{href}" title="Go to previous page" aria-label="Go to previous page">Prev</a>,
          <span class="prev disabled" aria-label="This is the first page">Prev</span>'
    next='<a class="next" rel="next" href="https://example.com{href}" title="Go to next page" aria-label="Go to next page">Next</a>,
          <span class="next disabled" aria-label="This is the last page">Next</span>'
    link='<li><a href="https://example.com{href}" title="Go to page {*}" aria-label="Go to page {*}">{*}</a></li>,
          <li class="current"><b title="Current page" aria-label="Current page">{*}</b></li>'
    gap='<li><span title="More pages" aria-label="More pages">…</span></li>'
    mask='{prev}{next}
    <ul class="pagination">
        {first}{<+}{links}{+>}{last}
    </ul>'
    />

可以实现完全自定义的HTML解决方案 - 此示例输出,如果有十一页且我们处于第五页,如下所示

<nav class="paginator" aria-label="Blog navigation">
    <a class="prev" rel="prev" href="https://example.com/blog/?pg=4" title="Go to previous page" aria-label="Go to previous page">Prev</a>
    <a class="next" rel="next" href="https://example.com/blog/?pg=6" title="Go to next page" aria-label="Go to next page">Next</a>
    <ul class="pagination">
        <li>
            <a href="https://example.com/blog/" title="Go to page 1" aria-label="Go to page 1">1</a>
        </li>
        <li>
            <span title="More pages" aria-label="More pages">…</span>
        </li>
        <li>
            <a href="https://example.com/blog/?pg=4" title="Go to page 4" aria-label="Go to page 4">4</a>
        </li>
        <li class="current">
            <b title="Current page" aria-label="Current page">5</b>
        </li>
        <li>
            <a href="https://example.com/blog/?pg=6" title="Go to page 6" aria-label="Go to page 6">6</a>
        </li>
        <li>
            <span title="More pages" aria-label="More pages">…</span>
        </li>
        <li>
            <a href="https://example.com/blog/?pg=11" title="Go to page 11" aria-label="Go to page 11">11</a>
        </li>
    </ul>
</nav>

etc_numpages标签

<txp:etc_numpages />

etc_numpages标签是一个单一辅助标签,用于计算各种列表(文章、图像、链接等)中的页数。

此标签通常用作pages属性值,传递给etc_pagination,如下所示

<txp:etc_pagination pages='<txp:numpages section="example" />' />

属性

大多数属性来自<txp:article />和其他Textpattern列表标签

  • limit="10"
    下面将介绍pageby的默认值。
  • offset="0"
    要排除的列表开头的项目数。
  • pageby="数字"
    每页的最大项目数。
  • table="txp_table"
    要从其中提取列表的Textpattern数据库表名。默认:textpattern(文章)。
  • total="数字"
    可选的列表长度,如果已知。
  • authorcategoryexcerptedexcludeexpiredidincludekeywordsmonthrealnamesectionstatustime
    这些属性在 txp:article_custom 以及其他 列表标签 中具有相同的功能。

示例

示例 1
<txp:if_individual_article>
    <txp:etc_pagination pgcounter="page" pages='<txp:etc_numpages section="news" />' />
</txp:if_individual_article>

此示例展示了在 news 部分内的单个文章页面上的分页(即,不是在文章列表上下文页面)。

etc_offset 标签

<txp:article_custom offset='<txp:etc_offset pgcounter="page" pageby="5" />' limit="5" />

用作辅助标签,用于计算文章|图片|…列表标签的偏移量。上面的示例将偏移量设置为 15,在带有 ...&page=4 URL 的页面上,因此 <txp:article_custom /> 将显示5篇文章中的第四页。

属性

  • pageby="10"
    每页的项目数量。
  • pgcounter="pg"
    作为页码的URL变量。
  • offset="0"
    可选的页面偏移。
  • type="value|page|start|end"
    输出 pgcounter 的原始(转义)、计算出的 页码起始页项目编号或 结束页项目编号。

示例

示例 1
Showing articles <txp:etc_offset type="start" /> to <txp:etc_offset type="end" />

输出 显示第3页的21至30篇文章,这是标准 <txp:article /> 列表。

作者/致谢

Oleg Loukianov 创作,并受到 ob1_pagination 的启发。感谢所有额外的贡献者