As a senior website operations expert, I am well aware of the foundational role of an efficient content management system (CMS) in website operations.AnQiCMS is excellent in content publishing and management with its concise and efficient architecture and rich features.paginationLabel, how to elegantly implement document list pagination display to optimize user experience and improve website performance.
AnQiCMS Pagination Feature Deep Guide: Clever UsepaginationTag implementation document list pagination
In content management, as the list content such as articles, products, or comments increases, users will face the problem of information overload if there is no effective pagination mechanism, and the website's loading speed will also be affected. AnQiCMS fully understands this and provides a set of intuitive and flexible pagination solutions, with the core being its powerfulpaginationLabel.
Understanding AnQiCMS's pagination mechanism:paginationCollaboration with list tags
Firstly, we need to clarify one point:paginationLabels do not operate independently; they always work closely with the tags used in AnQiCMS to obtain content lists, for examplearchiveList(Document List),commentList(Comment list) ortagDataList(Tag document list). When you set the parameters in these list tags,type="page"AnQiCMS will automatically prepare the data required for pagination of the current list. At the same time,limitParameters, you can precisely control the number of documents displayed per page. For example,{% archiveList archives with type="page" limit="10" %}This code will not only retrieve the first 10 documents but also prepare the pagination information for all documents.paginationUse the label.
paginationThe core function and parameter explanation of the tag.
Once the list label is ready for pagination data,paginationLabels shine on the stage, responsible for presenting these pagination information in a readable and clickable page number format on the front-end page. Its basic usage format is{% pagination pages with show="5" %}where,pagesIt is a variable name you define, used to receive pagination data;showIt is a very practical parameter that determines how many page number links are displayed before and after the current page number. For example,show="5"The meaning is that up to 5 page numbers will be displayed in the pagination navigation (excluding "Home
AnQiCMSpaginationThe tag also provides advanced parametersprefixIf you need to make unconventional customizations to the pagination URL structure, such as the default,?page=2to?p=2you can make use ofprefix="?p={page}"To implement. However, in most standard application scenarios, the default URL structure of AnQiCMS is already friendly enough, thereforeprefixthe parameters usually do not need to be manually set.
To delve deeper into the pagination data structure:pagesThe rich information of variables
When you usepaginationLabel and assign pagination data topagesAfter the variable,pagesThe object will contain a series of useful information, convenient for us to build a complete pagination navigation.
Firstly, it will provide global statistics, such asTotalItems(Total number of documents),TotalPages(Total number of pages) as well asEnglishPage(Current page number).This information can be used to display statistics like 'Total XX items, Page Y/Z' at the bottom of the page, helping users understand the overall scale of the current list.
Next,pagesVariable will also provide a series of convenient navigation link objects, includingFirstPage(Home page),LastPage(End Page)、PrevPage(Previous page) andNextPage(Next page)。Each navigation link object containsName(Link text, such as “Home”, “Previous page”)、Link(The actual URL address) andIsCurrent(A boolean value indicating whether it is the current page) properties. Through judgmentIsCurrentProperties, we can add a highlight style to the current page number to enhance user experience.
The most core isPages属性,it is an array that contains the list of page numbers in the middle section. You need to iterate over thisPagesarray to render each page number link, each array item also containsName/LinkandIsCurrentProperties. These fields make it easy to build dynamic and feature-rich pagination.
Practical Application of Pagination: Building a Complete Document List Pagination
To better illustratepaginationLabel's actual application, let's take a look at a combinationarchiveListThe typical code example for implementing document list pagination. Suppose we want to display 10 articles per page on the page and provide pagination navigation:
{# 1. 使用 archiveList 获取文档列表并准备分页数据 #}
{% archiveList archives with type="page" limit="10" %}
<div class="article-list">
{% for item in archives %}
<article class="post-item">
<h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
<p>{{ item.Description }}</p>
<div class="meta">
<span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
<span>阅读量:{{ item.Views }}</span>
</div>
</article>
{% empty %}
<p>当前分类下暂无文章。</p>
{% endfor %}
</div>
{# 2. 使用 pagination 标签生成分页导航 #}
<nav class="pagination-nav">
<ul>
{% pagination pages with show="5" %}
{# 显示首页链接 #}
<li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
<a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
</li>
{# 显示上一页链接,如果存在的话 #}
{% if pages.PrevPage %}
<li class="page-item">
<a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a>
</li>
{% endif %}
{# 遍历并显示中间页码链接 #}
{% for item in pages.Pages %}
<li class="page-item {% if item.IsCurrent %}active{% endif %}">
<a href="{{ item.Link }}">{{ item.Name }}</a>
</li>
{% endfor %}
{# 显示下一页链接,如果存在的话 #}
{% if pages.NextPage %}
<li class="page-item">
<a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a>
</li>
{% endif %}
{# 显示尾页链接 #}
<li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
<a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
</li>
{% endpagination %}
</ul>
</nav>
{% endarchiveList %}
In this code,archiveListresponsible for pulling data and informing the system that pagination is needed (type="page"). Then,paginationTag utilizationpagesvarious information contained in the variable dynamically generates a complete page navigation. Through conditional judgment ({% if %}and{% if item.IsCurrent %}We can ensure that the "Previous/Next Page" links are displayed only when needed and add special styles to the current page number.
**Practice and Advanced Techniques**
- Always use
type="page"This is the key to trigger the AnQiCMS to generate pagination data. If it is forgotten to set,paginationthe tag will not be able to obtain any pagination information. - Reasonable settings
limitWithshow:limitControl the number of items displayed per page, which directly affects the user's browsing experience and page loading speed.showControls the length of page number navigation to avoid redundancy. Adjust according to website content and user habits. - CSS style customization:
paginationThe label only generates HTML structure, and its appearance is completely controlled by front-end CSS.This provides great freedom for designers, allowing them to customize the design according to the overall style of the website. - SEO friendly:AnQiCMS in generating pagination URLs usually follows SEO **practices, such as in