How to create a customizable pagination component for the document list in Anqi CMS template?

Calendar 👁️ 67

It is crucial to display and manage document lists efficiently when building a content-rich website.Especially for sites with a large amount of content, a well-designed and functional pagination component can not only greatly improve user experience, but also optimize the website's SEO performance, helping search engines better crawl and index content.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag features, allows us to easily create highly customizable pagination components for document lists.

The AnqiCMS template system adopts a syntax similar to Django template engine, through{% 标签 %}to handle logic,{{ 变量 }}to output content. When implementing pagination, we mainly use two core tags:archiveList(Document list tag) andpagination(Pagination tags). These tags work together, the former is responsible for fetching document data from the database by page, and the latter generates operable page navigation based on this data.

First step: Prepare pagination data source - UsearchiveListTag

To create a paged document list, you first need to tell Anqi CMS that you want to retrieve data in the form of pagination. This is done byarchiveListlabel'stype="page"To implement the parameter. Whentypeis set topagethen,archiveListIt is no longer simply a list of all qualified documents, but will retrieve data according to the current page number and the set number of documents per page, and at the same time forpaginationLabel the necessary pagination information.

For example, if we want to get the list of articles under a certain category and want to display 10 articles per page, the template code might look like this:

{% archiveList archives with type="page" categoryId="1" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{ item.Link }}">{{ item.Title }}</a>
        <p>{{ item.Description }}</p>
        <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
    </li>
    {% empty %}
    <li>暂无内容</li>
    {% endfor %}
{% endarchiveList %}

In this code block,archivesThe variable contains the document data of the current page, we can traverse it like a normal list.categoryId="1"Specified the category ID,limit="10"Then set to display 10 articles per page.

Step two: Build the pagination navigation component - DeeplypaginationTag

InarchiveListAfter the tag generates the pagination data, you can use it immediatelypaginationThe tag can be used to build the actual page number navigation.paginationThe tag will automatically obtain byarchiveListThe pagination context information provided by (or other pagination data source tags) allows us to finely control the display of page numbers.

paginationThe usage of tags is typically to wrap them in a container element and it provides an object namedpagesthis object, itpagesAn object contains all the detailed information related to pagination, such as:

  • TotalItemsTotal number of documents:
  • TotalPagesTotal number of pages:
  • CurrentPageCurrent page:
  • FirstPageThe home page object includes:NameandLink)
  • LastPageThe end page object includesNameandLink)
  • PrevPageThe previous page object includesNameandLink)
  • NextPageThe next page object includesNameandLink)
  • PagesAn array of middle page number objects, each withName(page number),Link(link address) andIsCurrent(whether it is the current page) attribute.

paginationThe tag supports a very practical parameter:show.showThe parameter is used to control how many page number links are displayed at the same time in page navigation, for exampleshow="5"This means that up to 5 consecutive page numbers can be displayed.

Now, let's look at a complete, customizable pagination component example:

<div class="pagination-container">
    {% archiveList archives with type="page" categoryId="1" limit="10" %}
        <ul class="document-list">
        {% for item in archives %}
            <li>
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p>{{ item.Description }}</p>
                <div class="meta">
                    <span>发布于:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span>
                    <span>阅读量:{{ item.Views }}</span>
                </div>
            </li>
        {% empty %}
            <li class="no-content">当前分类暂无文档。</li>
        {% endfor %}
        </ul>

        {% pagination pages with show="7" %}
            <nav class="page-numbers">
                <ul>
                    {# 显示首页链接 #}
                    <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 %}current{% 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>
                </ul>
                <div class="page-info">
                    <span>总计 {{ pages.TotalItems }} 篇文档,共 {{ pages.TotalPages }} 页</span>
                    <span>当前第 {{ pages.CurrentPage }} 页</span>
                </div>
            </nav>
        {% endpagination %}
</div>

Code analysis:

  • archiveListLabel:The outer layer is used firstarchiveListGet the documents that need pagination.type="page"Is the key, it activates the pagination mode.
  • pagination pages with show="7":Following it,paginationThe tag is called, and the pagination data is assigned topagesVariable.show="7"It means that in addition to the first page, last page, previous page, and next page, at most 7 consecutive page numbers can be displayed.
  • Home, Last Page, Previous Page, Next Page:Bypages.FirstPage/pages.LastPage/pages.PrevPageandpages.NextPageObjects, we can easily build these navigation links.{% if %}Ensure that the link is rendered only when these pages exist (for example, not on the first page), otherwise the previous page is displayed.
  • Middle page number: {% for item in pages.Pages %}

Related articles

How to judge whether the comment is under review and display it conditionally using the `commentList` tag?

In website operation, comments are an important element in enhancing user interaction and community vitality.However, it is an indispensable link to review the comments submitted by users to ensure the health and quality of the website content.How can we flexibly display these comments in AnQi CMS, especially when they are still in the review stage, which has become a concern for many operators.It's good that AnQi CMS template tag system provides us with strong control, especially the `commentList` tag, which can help us easily implement conditional display of comments.

2025-11-08

How to display a document's comment list in Anqi CMS template, including reply and pagination features?

In Anqi CMS, add a comment list to the document content and enable it to have reply and pagination functions, which can greatly enhance the user interaction of the website.Users can express their opinions and discuss specific documents, which not only enriches the content ecosystem but also brings more vitality to the website. ### One: Displaying Comment Lists: The Foundation of Interaction To display comments on a document page, it mainly relies on the `commentList` tag built into Anqin CMS.This tag helps us easily get the comment data associated with the current document. First

2025-11-08

How to dynamically generate a custom field comment form with `guestbook` tag and adapt to different input types?

Managing website comments in Anqi CMS is a common requirement in daily operations, especially when we need to collect specific information, a flexible and customizable comment form becomes particularly important.Aqie CMS fully considers this requirement and provides a powerful `guestbook` tag, allowing us to easily dynamically generate a feedback form with custom fields and adapt to various input types.The power of the `guestbook` form label The core lies in the `guestbook` tag

2025-11-08

How to determine if the current navigation item is the current page in the `navList` loop?

In website operation, a clear navigation structure is crucial for improving user experience.A good navigation not only helps visitors quickly find the information they need, but also guides users through visual cues (such as highlighting the current page) so that they always know where they are.In AnQi CMS, implementing this feature is quite intuitive and efficient, which is due to its powerful template tag system.

2025-11-08

How to get the current page number, total number of pages, and home/last page links for the `pagination` tag?

AnQiCMS (AnQiCMS) is a powerful content management system that provides flexible and diverse ways to display content when building a website.Among them, the pagination function is crucial for list pages with a large amount of content, as it not only improves the user experience but also optimizes the website performance.Proficiently use the `pagination` tag, which can help us accurately control the display logic of pagination, thereby creating a more user-friendly and professional website.

2025-11-08

How to list all documents under a specific tag in AnQi CMS template and support pagination?

In a content management system, effectively organizing and displaying articles is the key to improving user experience.When content is categorized through tags, we often need to list all the articles under a specific tag on a page, and to maintain the cleanliness and loading speed of the page, pagination functionality also becomes indispensable.Strong and flexible template tags provided by AnQi CMS make this requirement easy to achieve.

2025-11-08

How to display document, category, or single page associated image groups (such as Banner galleries) in Anqi CMS template?

At the time of building a website, exquisite image sets, such as carousel banners, are important elements to attract visitors' attention and display core content.AnQiCMS (AnQiCMS) provides flexible and powerful template functions, allowing you to easily display these groups of images associated with documents, categories, or single pages on the website.This article will delve into how to call and display these image groups in Anqi CMS templates, helping you better utilize visual content to enhance the attractiveness of your website.---###

2025-11-08

What is the practical use of the `dump` filter in AnQi CMS template debugging?

During the development and maintenance of Anqi CMS templates, we often encounter situations where some data cannot be displayed correctly or the variable structure does not match the expected one.How can one quickly and effectively find the source of the problem, which is a challenge facing every template developer.Fortunately, AnQi CMS provides an extremely useful tool—the `dump` filter, which can help us penetrate the true appearance of variables in the template like X-ray.What is the `dump` filter?

2025-11-08