How to implement pagination display of document list in AnQiCMS template using `pagination` tag?

Calendar 👁️ 60

As an experienced CMS website operator, we understand that it is crucial to efficiently display a large amount of content and ensure a user-friendly browsing experience in a content management system.For a document list, pagination display is the core function to achieve this goal.paginationThe tag plays a key role in connecting the document list with page navigation, enabling a large number of documents to be presented to the user in a structured manner while maintaining flexibility and customizability.

To understandpaginationThe principle of the label, we first need to clarify the content list it depends on. In AnQiCMS, such asarchiveList(Document list),tagDataList(Tag associated document list) andcommentList(Comment list) tags, if pagination is required, it must be theirtypethe parameter topage. For example, when we want to display documents in a paginated list of articles, we will usearchiveListtags, and specifytype="page"Approved at the same timelimitParameter setting the number of documents displayed per page.

Once the content list tag is configured astype="page,AnQiCMS system will handle all the data required for pagination in the background and pass these data to the template. At this time,paginationThe role of the tag is highlighted, it is responsible for converting these pagination data into actual pagination navigation links visible on the user interface.

paginationThe basic method of using the tag is{% pagination pages with show="5" %}...{% endpagination %}. Here,pagesIt is an automatic pagination data object filled by the system, whileshowThe parameter allows us to control the maximum number of page link navigation displayed, such asshow="5"Means showing up to 5 page numbers around the current page. Additionally, it has a advanced parameterprefixUsed to redefine the pagination URL pattern, but usually we do not need to adjust it manually.

paginationTags inside provide a rich set of fields for template developers to call, to build flexible pagination navigation. These fields includeTotalItems(Total number of entries),TotalPages(Total number of pages),CurrentPage(Current page number) and other basic information. What's more, it also provides page objects pointing to specific pages:FirstPage(Home page),LastPage(End page),PrevPage(Previous page) andNextPage(Next page). These page objects themselves containName(Link name),Link(link address) andIsCurrent(Whether the current page) and other properties, making it convenient for us to directly generate navigation links and mark the current page.

To display the middle page number,paginationthe label provides a namedPagesarray. ThisPagesarray contains all clickable page number objects, we can useforLoop through it and, based on the properties of each page objectIsCurrentdetermine whether it is the current page and assign different styles accordingly.

Integrate all this together, a typical document list pagination display will be like this: First, we usearchiveListtags to obtain the pagination document data, and then inendarchiveListthe tag, then immediately usepaginationTags to render pagination navigation.

{# 首先,使用 archiveList 标签获取分页文档列表 #}
<div>
{% archiveList archives with type="page" limit="10" %}
    {# 遍历文档列表,显示每篇文档的标题、描述等信息 #}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <div>{{item.Description}}</div>
            <div>
                <span>{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>{{item.Views}} 阅读</span>
            </div>
        </a>
        {% if item.Thumb %}
        <a href="{{item.Link}}">
            <img alt="{{item.Title}}" src="{{item.Thumb}}">
        </a>
        {% endif %}
    </li>
    {% empty %}
    <li>
        当前分类或搜索条件下没有任何文档。
    </li>
    {% endfor %}
{% endarchiveList %}

    {# 紧接着,使用 pagination 标签渲染分页导航 #}
    <div class="pagination">
        {% pagination pages with show="5" %}
        <ul>
            {# 显示总条目数、总页码数、当前页码等统计信息 #}
            <li>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>
            {# 渲染首页链接,并根据 IsCurrent 属性添加激活样式 #}
            <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 %}
            {# 渲染末页链接,并根据 IsCurrent 属性添加激活样式 #}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
            </li>
        </ul>
        {% endpagination %}
    </div>
</div>

By using the above combination, we not only achieved pagination display of the document list, but also provided users with a clear and intuitive navigation method.This flexible tag design makes the template creation of AnQiCMS efficient and flexible, whether it is for SEO-friendly URL structures or to optimize user experience, it can easily cope with it.


Frequently Asked Questions (FAQ)

In AnQiCMS templatepaginationWhy may the tag not display or display incorrectly?paginationThe tag needs to be used with list tags that support pagination features such asarchiveList/tagDataListorcommentListAnd these tagstypeThe parameter must be set topagemust work properly. If these prerequisite conditions are not met, orlimitthe parameter settings are incorrect (for example, the number of items per page is too large, causing the total number of pages to be insufficient to trigger pagination),paginationThe label may not be rendered.

How to customizepaginationThe pagination navigation style generated by the label?paginationThe tag is only responsible for providing pagination data and link structure, the specific style needs to be controlled by CSS. In the provided example code, we added to the pagination container.paginationAdd class to each page itempage-itemAdd class to the current pageactiveClasses. You can define your own styles using these class names in the CSS file, such as setting the background color, font size, margin, and highlighting effect of the current page number.

paginationCan the tag be used for pagination of any list data? The document clearly states,paginationThe tag is used to retrievepagination information for article lists, product lists,and is also inarchiveList/tagDataListandcommentListThe document mentions that it willtypeis set topagecan be used subsequentlypaginationThis means it is mainly designed for these pageable content lists built into the system, it may not be directly usable for other customized or non-list type datapaginationTagging for pagination. If pagination is needed for other data, it is usually necessary to perform additional data processing at the controller level and manually construct the pagination logic.

Related articles

How to get the contact information configured in the `contact` tag of AnQiCMS template?

As an experienced website operator for Anqi CMS, I am well aware of the core position of content in website construction and user interaction.Effectively and conveniently displaying contact information is an indispensable part of a website's functionality, directly affecting the efficiency and willingness of users to communicate with the company.In AnQiCMS, we provide a simple and powerful template tag——`contact`, allowing you to easily display the contact information configured in the background on the website front-end.--- ###

2025-11-06

How to use the `stampToDate` tag to format timestamps in AnQiCMS templates?

As an experienced website operator deeply familiar with Anqi CMS, I know the importance of content timeliness and presentation for user experience.In website content management, the timestamp (Timestamp) is a common way to record the time of content publication and update, but displaying the timestamp directly is not intuitive for users.Therefore, formatting timestamps into readable date and time formats is a key factor in enhancing the professionalism and user-friendliness of a website.AnQiCMS provides a very convenient template tag `stampToDate`, making this operation effortless

2025-11-06

How to set the page title, keywords, description, and attach the website name using the `tdk` tag in AnQiCMS?

As a senior security CMS website operator, I am well aware of the core position of content in website construction and SEO optimization.TDK (Title, Description, Keywords) tags are an important basis for search engines to understand page content and judge the relevance of the page, as well as the information that users see first on the search results page.Efficiently setting and optimizing TDK is crucial for attracting target users and improving website rankings.Our Anqi CMS provides us with flexible and powerful TDK management functions, allowing us to finely control the metadata of each page

2025-11-06

How to use the `system` tag to obtain website name, LOGO, filing number and other system information?

As an experienced CMS website operation personnel, I fully understand the importance of dynamically obtaining basic website information in daily template development and content presentation.To ensure the consistency, ease of maintenance, and efficient management of the website, Anqi CMS provides an extremely convenient `system` tag.This tag allows template developers to directly call various system-level data from the global settings in the background, thereby avoiding the inconvenience brought by hard coding.The website's name, logo, filing number, and other information are key elements in building a brand image and legal compliance.Pass through the `system` tag

2025-11-06

What is the difference between the `safe` and `escape` template filters in AnQiCMS and when should they be used?

As an experienced website operator for AnQiCMS, I am well aware that the correct use of templates is crucial for the safety and display effect of the website during content creation and publishing.AnQiCMS's powerful template engine provides rich features, among which the `safe` and `escape` filters play a key role in handling HTML special characters during content output.Understanding the differences and proper application is the foundation for ensuring website content security and enhancing user experience.###

2025-11-06

Which operating systems does AnQiCMS support for installation?

AnQiCMS is an enterprise-level content management system developed based on the Go language, dedicated to providing efficient, customizable, and easily scalable content management solutions for small and medium-sized enterprises, self-media operators, and those who need to manage multiple sites.Its lightweight architecture and excellent performance make AnQiCMS highly compatible in deployment and operation.As an experienced website operator, I am well aware of the importance of choosing a system with strong compatibility to ensure the stable operation of the website.Next, we will discuss AnQiCMS in detail

2025-11-06

How to manually deploy AnQiCMS on a Linux server?

As an experienced website operations manager, I am well aware of the importance of a stable and efficient content management system for the development of a company.AnQiCMS with its excellent performance in Go language and many enterprise-level features, has become an ideal choice for many small and medium-sized enterprises and content operation teams.Deploy AnQiCMS on a Linux server to fully utilize its high performance and security advantages.The following will elaborate on the steps and key points for manually deploying AnQiCMS on a Linux server, aiming to help you smoothly set up and run your content platform.###

2025-11-06

How to quickly install AnQiCMS on Baota panel?

Hello!As an expert in AnQiCMS operation, I fully understand your need for a quick and efficient website construction.AnQiCMS with its excellent performance brought by the Go language and enterprise-level features is becoming a new choice for more and more operators.BtPanel is a widely popular server management tool that greatly simplifies the deployment process of AnQiCMS.

2025-11-06