How to implement pagination display of content lists in AnQi CMS?

Calendar 👁️ 75

In Anqi CMS, the pagination display of the content list is one of the key functions to improve user experience, optimize website performance, and facilitate content management.AnQi CMS, with its flexible template tags and powerful content management capabilities, provides us with a simple and efficient way to meet this requirement.

The importance of displaying pagination in content lists

Imagine if your website had tens of thousands of articles, products, or comments all displayed on one page, not only would it make the page load speed incredibly slow, but it would also make users lose their way in the vast amount of information.The pagination display can split a large amount of content reasonably into multiple pages, greatly reducing the burden on a single page, optimizing the loading speed, and also allowing users to browse as needed, improving the overall user experience.For search engines, a clear pagination structure also helps them better understand and index website content.

The Anqi CMS template engine is designed to be intuitive and easy to use, it adopts syntax similar to the Django template engine, through specific tags({% tag %})to handle logic, and use double curly braces({{ variable }})to output variables, making it easy for even users without a strong development background to get started quickly.

Core tags:archiveListwithpagination

In Anqi CMS, the implementation of content list pagination depends mainly on two core template tags:

  1. archiveListDocument List Tags: is used to retrieve and display the document content list.
  2. paginationPagination LabelUsed for rendering pagination navigation links, allowing users to jump between different pages.

Below, we will step by step introduce how to combine these two tags to achieve pagination display of content lists.

First step: usearchiveListTag to get pagination data

archiveListTags are the main tool you use to get a list of articles, products, and other content. To implement pagination, you need to specify the pagination behavior throughtypeandlimitthe parameter:

  • type="page"This parameter tells Anqi CMS that you want to retrieve a list that can be paginated. The system will use the page number parameter in the current page URL (such as?page=2) Auto-adjust the returned data.
  • limit="N": This parameter defines how many items are displayed per page. For example,limit="10"This means 10 items are displayed per page.

Here is a basicarchiveListLabel usage example, used to obtain the article model (moduleId="1") content list, ready for pagination, displaying 10 items per page:

{% archiveList archives with type="page" moduleId="1" limit="10" %}
    {% for item in archives %}
        <div class="article-item">
            <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
            <p class="summary">{{ item.Description }}</p>
            <div class="meta">
                <span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>阅读量: {{ item.Views }}</span>
                <span>分类: <a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></span>
            </div>
        </div>
    {% empty %}
        <p>抱歉,当前分类或搜索条件下暂无内容。</p>
    {% endfor %}
{% endarchiveList %}

In the code above:

  • archivesIs your custom variable name, used to store the list of obtained documents.
  • moduleId="1"Represents the content under the article model with ID 1. You can adjust it according to your own content model ID.
  • item.Link/item.Title/item.DescriptionisarchivesCommon properties of each document item. You can also accessitem.Views(Views),item.Thumb(thumbnail) and more properties.

Second step: usepaginationThe label renders pagination navigation

InarchiveListAfter the tag, you need to usepaginationLabel to generate pagination navigation bar. This label will automatically handle the current page number, total number of pages, and generate correct page link links, etc.

  • show="N"This parameter is used to control how many page number digits are displayed on the pagination navigation bar, in addition to the first page, last page, previous page, and next page. For example,show="5"It will display the current page and nearby 5 page numbers in the navigation.

The following is a standard and fully functionalpaginationLabel usage example:

<div class="pagination-container">
    {% pagination pages with show="5" %}
        <ul>
            <li class="info">总共:{{ pages.TotalItems }} 条内容,{{ pages.TotalPages }} 页,当前第 {{ pages.CurrentPage }} 页</li>
            
            {# 首页链接 #}
            <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 pageItem in pages.Pages %}
                <li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
                    <a href="{{ pageItem.Link }}">{{ pageItem.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>
    {% endpagination %}
</div>

In the above code:

  • pagesIspaginationVariable generated by the tag, which contains all the data related to pagination.
  • pages.TotalItems/pages.TotalPages/pages.CurrentPageThey represent the total number of items, total pages, and the current page number.
  • pages.FirstPage/pages.PrevPage/pages.NextPage/pages.LastPageThey are objects that includeName(Link text, such as "Home", "Previous page") andLink(Jump links).
  • pages.Pagesis an array that contains the page numbers in the middle section, you need toforloop through it to display each page number.pageItem.IsCurrentCan determine if the current page number is the current page, convenient for you to add highlight styles.

Combined example: complete pagination display code

Combine these two tags and you can implement a complete content list pagination function in the AnQi CMS template. Usually, such code is placed on the category list page ({模型table}/list.html) or search results page (search/index.html).

``twig <!DOCTYPE html>

<meta charset="UTF-8">
<title>{% tdk with name="Title" siteName=true %} - {% system with name="SiteName" %}</title>
<style>
    /* 简单的分页样式,您可以根据网站设计自由调整 */
    .pagination-container ul {
        list-style: none;
        padding: 0;
        display: flex;
        justify-content

Related articles

How to format and display timestamps as readable dates or times in templates?

In the daily operation of AnQi CMS, we often need to handle various data, among which time information is undoubtedly the most common and important kind.Whether it is the publication date of the article, the update time, or the specific moment of user comments, these time data are usually stored in the form of timestamps.However, the original timestamp is not intuitive for ordinary users; they are more like a string of meaningless numbers.At this point, it becomes particularly important to convert these timestamps into a date or time format that is easy to understand.The Anqi CMS template system uses a syntax similar to the Django template engine

2025-11-08

How to implement the switching display of multilingual website content?

In today's globalized digital environment, making a website support multiple language display is no longer an option, but a necessity for many enterprises and content operators to expand international markets and improve user experience.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, integrating powerful multilingual support features to help us easily switch between different language displays on the website.How can we specifically operate to enable multilingual content switching capabilities for our Anqi CMS website?This can mainly be found in the system language package

2025-11-08

How to display and manage the display of images and video multimedia resources?

In website operation, high-quality multimedia content is the key to attracting visitors and improving user experience.AnQiCMS (AnQiCMS) is well-versed in this, providing comprehensive features to help users easily manage and flexibly display images and videos on their websites.From unified resource library to intelligent optimization settings, AnQiCMS makes multimedia management efficient and convenient. ### One, Core Multimedia Management Center: Image Resource Management Anqi CMS gathers all uploaded images and video resources into a centralized "Image Resource Management" module.This is not only the place where you store your materials

2025-11-08

How to display single page content on the front end of a website (such as About Us, Contact Us)?

In website operation, single-page content like "About Us" and "Contact Us" is indispensable, as it carries important functions such as displaying corporate image, providing contact information, or stating service terms.For friends using AnQiCMS, it is actually a very direct and flexible thing to beautifully display these single-page contents on the website front end. ### Single Page Content Management Overview Firstly, we need to create and manage these single pages in the AnQiCMS backend system.In the left navigation bar of the background, you can find the "Page Resources" menu

2025-11-07

How to display the website's friend link list on the front end?

In website operation, friendship links play an indispensable role.They not only help improve the quality of a website's external links, enhance search engine optimization (SEO) effects, but also bring additional traffic to the website and increase its credibility through peer recommendations.Our CMS understands the importance of friendship links, therefore, it provides an intuitive and convenient management function, and supports flexible front-end display methods, allowing website administrators to easily present these important cooperative resources on the page.### One, Friendship Link Management in AnQi CMS In the AnQi CMS backend management interface

2025-11-08

how to display the captcha in the message or comment function?

In website operation, the message and comment functions are important channels for interaction with users, but they often become hotbeds of spam and malicious flooding.It is particularly important to add captcha to these interactive functions to maintain a clean and high-quality communication environment.AnQi CMS understands this and provides a convenient solution for it.How can you display a captcha in the Anqi CMS message or comment feature to effectively resist spam?This mainly consists of two core steps: first, enable the captcha feature in the background, and then integrate the captcha element into the front-end template.### Step 1

2025-11-08

How to display the user message or article comment list and handle the review status?

In website operation, user comments and article reviews are an important part of promoting interaction and enhancing content value.For users of Anqi CMS, it is crucial to display user-generated content reasonably and manage their review status effectively to ensure the quality of website content and user experience.We will discuss in detail how to achieve this goal in Anqi CMS. ### Learn about comment and message management in Anqi CMS Anqi CMS provides users with convenient content comment and website message management features.In the background management interface

2025-11-08

How to configure and display the article Tag tag list in AnQi CMS?

In website operation, Tag tags (also known as keyword tags) are a very practical way to organize content, which can help users quickly find related content and also improve the SEO effect of the website content.AnQiCMS (AnQiCMS) provides a comprehensive Tag label configuration and display function, making it easy and efficient to manage and display these tags.Below, let's take a detailed look at how to set up and use these tags in AnQiCMS.--- ### One, background configuration and management of article Tag label In AnQiCMS

2025-11-08