【发布时间】:2022-01-13 08:17:49
【问题描述】:
我想问一下如何限制页面,例如,如果我只想要分页中的 4 页,然后是箭头。现在它显示了所有页面:
这是我现在使用的代码:
{% if posts.lastPage > 1 %}
<div class="pagination">
<ul>
{% if posts.currentPage > 1 %}
<li><a class="pagination--left-arrow"href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage-1) }) }}">←</a></li>
{% endif %}
{% for page in 1..posts.lastPage %}
<li class="{{ posts.currentPage == page ? 'active' : null }}">
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
</li>
{% endfor %}
{% if posts.lastPage > posts.currentPage %}
<li><a class="pagination--right-arrow"href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage+1) }) }}">→</a></li>
{% endif %}
</ul>
</div>
{% endif %}
【问题讨论】:
-
你可以添加像
{% set toPage = posts.currentPage + 3 %} {% for page in posts.currentPage..toPage %}这样的中间循环..并为currentPage添加默认值意味着如果它没有设置为1..左右 -
并调整变量,使
the current page按钮停留在中间而不是第一个可能...
标签: php content-management-system octobercms