How to implement pagination functionality in AnQiCMS

Calendar 👁️ 76

For any website that carries a large amount of content, how to efficiently and friendly display these contents is undoubtedly one of the keys to successful operation.When the number of articles, products, tag pages, and other content is large, it is obviously unrealistic to stack them all on a single page, not only will the loading speed be slow, but users will also find it difficult to find the information they need.At this point, the pagination function becomes particularly important.

In AnQiCMS, implementing pagination is quite intuitive and flexible.It cleverly combines the acquisition of content lists with the display of pagination navigation, making the organization and presentation of website content both beautiful and efficient.

Core Concept: The perfect combination of list and pagination

In AnQiCMS, the pagination feature is not isolated, it is closely connected with the content list call.This means that you first need to obtain the data that needs to be displayed with pagination by means of the corresponding content list tags.For example, in the list of the most commonly used articles, we usually usearchiveList.

when you wisharchiveListThe data returned by the label is paginated, not displayed all at once or only a fixed number at a time, just set it in the labeltype="page"the parameters, and specify the number of items per pagelimitFor example, if you want to display a list of articles on a page and show 10 articles per page, you can write the code like this:

{% archiveList archives with type="page" limit="10" %}
    {# 这里是您的文章列表循环代码 #}
    {% for item in archives %}
        <div class="article-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
            <span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </div>
    {% empty %}
        <p>暂时没有文章内容。</p>
    {% endfor %}
{% endarchiveList %}

This code will inform AnQiCMS to retrieve the list of article data, but not to provide it all at once, but to provide it in batches by page, with a maximum of 10 items per page. ThrougharchivesThis variable, you can iterate over the articles on the current page as usual.

Building pagination navigation:paginationMagic of tags

Just getting a list of articles that can be paginated is not enough, the user also needs to see the page navigation buttons on the page. The powerful feature is responsible for generating the page navigation buttons and links.pagination.

paginationThe label usually follows its corresponding list label. It automatically reads the pagination information of the current page (such as total number of pages, current page number, home link, previous page link, etc.), and then renders a beautiful pagination navigation according to your configuration.

This tag is the most commonly used parametershowIt determines the maximum number of page buttons displayed in pagination navigation. For example,show="5"This means that 5 page numbers will be displayed before and after the current page number.

While usingpaginationWhen a tag is used, it will encapsulate all pagination information in a variable namedpages, and you can access all data related to pagination through this variable, for example:

  • pages.TotalItems: Total number of contents.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: The current page number.
  • pages.FirstPage: Home object, includingLink(Link) andName(Name), as well asIsCurrent(whether it is the current page).
  • pages.LastPage: End page object, similar in structure to the home object.
  • pages.PrevPage: Previous page object, similar in structure to the home object.
  • pages.NextPage: The next page object, similar in structure to the home page object.
  • pages.Pages: An array of objects containing all the intermediate page numbers (usually a few pages around the current page number), each object also containsLink/NameandIsCurrent.

You can use this information to highly customize your pagination style.

Practical exercise: Step-by-step implementation of pagination

Now, let's combine the article list with the pagination navigation, and see what the complete pagination implementation code roughly looks like:

{# 1. 使用 archiveList 标签获取可分页的文章数据 #}
{% archiveList archives with type="page" limit="10" %}
    <div class="article-list">
        {% for item in archives %}
            <div class="article-item">
                <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
                <p>{{item.Description}}</p>
                <span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量: {{item.Views}}</span>
            </div>
        {% empty %}
            <p>暂时没有文章内容。</p>
        {% endfor %}
    </div>
{% endarchiveList %}

{# 2. 使用 pagination 标签生成分页导航 #}
<div class="pagination-nav">
    {% pagination pages with show="5" %}
    <ul>
        {# 首页链接,如果当前是首页则添加 active 样式 #}
        <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 %}

        {# 末页链接,如果当前是末页则添加 active 样式 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
            <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
    <p class="page-info">
        共 {{pages.TotalItems}} 条内容,当前第 {{pages.CurrentPage}} / {{pages.TotalPages}} 页
    </p>
    {% endpagination %}
</div>

In this code block,archiveListResponsible for content filtering and batching,paginationIt is responsible for displaying page numbers, home page, end page, previous page, next page, and other navigation elements. By judgingIsCurrentattribute, you can easily add highlight styles to the current page number to enhance the user experience.

It's not just a list of articles: pagination for more scenarios

The pagination logic of AnQiCMS is unified and flexible. In other scenarios where you need to display content in bulk, such as product lists (if the content model defines products), tag document lists, or even comment lists, you can use a similar approach.type="page"The parameter withpaginationThe combination of labels to implement pagination.

For example, to get a list of documents under a certain Tag and paginate, you can usetagDataListTags:

{% tagDataList archives with type="page" limit="15" %}
    {# 标签下的文档列表循环 #}
    ...
{% endtagDataList %}
{% pagination pages with show="7" %}
    {# 分页导航 #}
    ...
{% endpagination %}

This consistency makes template development and maintenance simpler, you only need to master a set of pagination patterns to meet the diverse content pagination needs of AnQiCMS.

Summary

AnQiCMS implements pagination functionality with full consideration of convenience and scalability. By simply setting parameters in the content list tagstype="page"andlimitand combining powerful features withpaginationTags, you can easily add professional and smooth pagination navigation to your website content.This not only improves the user browsing experience, but also helps to structure the website content and optimize search engine optimization, allowing your website to stand out in the information flood.


Frequently Asked Questions (FAQ)

How to modify the number of articles/products displayed per page?

You can adjust the parameter value in the content list tag (such asarchiveList/tagDataList) to modify the number of items displayed per page. For example, to adjust thelimitvalue of the parameter.limit="10"changed tolimit="20"This will allow 20 items to be displayed per page.

2. Can the URL structure of pagination links be customized? For example, to/list-1.html?page=2changed to/list-1_2.html?

Yes, AnQiCMS provides powerful static rule management functions.You can find the 'Static Rule' under the 'Feature Management' menu in the background, where you can choose or customize a URL structure that meets your needs, including integrating pagination parameters into the URL path.For example, in the custom rule, pagination page number{page}It can be placed within parentheses, such as:(-{page})This allows the page number to be displayed in the form of/list-1-2.htmlSuch a form of display.

3. Besides articles and products, what types of content support pagination?

The pagination feature of AnQiCMS is universal. In addition to common articles (archiveList)and custom content models (such as products), it also supports document lists under tags(tagDataList)and website content comment lists(commentList)with pagination. As long as the corresponding content list tags supporttype="page"Parameters, you can cooperatepaginationTags can be used to achieve pagination effects.

Related articles

How to display custom contact information on the website frontend, such as WhatsApp or Facebook links?

In today's digital age, allowing customers to easily find and contact you is the cornerstone of any successful website.Whether it is to provide customer support, promote sales, or build community interaction, clear and visible contact information is crucial. 幸运的是,AnQi CMS provides a set of intuitive and powerful features that allow you to easily display various custom contact methods on your website front-end, such as WhatsApp or Facebook links, ensuring that your customers can always communicate with you conveniently.Next, we will step by step introduce how to achieve this goal in Anqi CMS

2025-11-09

How to set up scheduled article publishing in AnQiCMS to achieve automated content display?

In today's internet age where content is king, the continuous update and efficient operation of website content is the key to attracting and retaining users.However, manual timed release is not only time-consuming and labor-intensive, but may also miss the**release opportunity due to negligence.AnQiCMS addresses this pain point by building a convenient scheduled publishing function, which helps us easily achieve automated content display.Why choose scheduled publication to achieve content automation?Timely publishing is not only a tool to improve efficiency, but also an indispensable part of content operation strategy.The benefits it brings are obvious: *

2025-11-09

Does AnQiCMS provide a feature for dynamically displaying the current year tag?

In the daily operation of website content, we often encounter some elements that need to be dynamically updated, the most common of which is the year in the copyright statement.If you need to manually change the year at the bottom of the website every year, it not only takes time and effort, but is also prone to omissions.As a pursuit of efficient and intelligent content management system, can AnQiCMS provide us with a solution to automatically update the current year?The answer is affirmative. AnQiCMS fully considers these subtle needs in website operation and has built-in corresponding tag functions for its template engine.

2025-11-09

How to safely output the article content containing HTML tags in a template, preventing XSS attacks while maintaining the format?

In website content operation, we often need to publish articles containing images, links, paragraph styles, and other rich formats.AnQiCMS (AnQiCMS) is a powerful content management system with a flexible template engine that can help us easily display these contents.However, while enjoying the convenience, we must also pay attention to a core issue: how to safely output the article content with HTML tags in the template, while maintaining its original beautiful format and effectively preventing potential cross-site scripting (XSS) attacks

2025-11-09

How to safely escape URL parameters in AnQiCMS templates to avoid potential risks?

When building and operating a website, URL (Uniform Resource Locator) parameters play a crucial role, helping us to achieve dynamic content display, filtering, and navigation functions.However, improper handling of URL parameters may also become a major security vulnerability for websites.This article will deeply explore how to safely escape URL parameters in the AnQiCMS template to effectively avoid potential risks.### The security risks of URL parameters should not be overlooked URL parameters usually carry user input or data generated by the system, such as search keywords, category ID

2025-11-09

How to specifically apply the `urlencode` filter to URL parameters in AnQiCMS templates?

In AnQiCMS template development, building dynamic URLs is a common requirement.Whether it is linking to the search results page, filtering list, or passing specific parameters to the backend service, the correctness of the URL is crucial.This is when the `urlencode` filter becomes a key tool to ensure that URL parameters are valid and secure. ### The Importance of URL Encoding URL (Uniform Resource Locator) has a strict character specification.In a URL, some characters have special meanings, such as `/` for path separation, `?

2025-11-09

What are the differences in application scenarios between the `iriencode` filter and `urlencode` in AnQiCMS templates?

In AnQiCMS template development, URL encoding is a detail that should not be overlooked.It not only affects the validity of the link, but also is closely related to the website's search engine optimization (SEO) and user experience.AnQiCMS provides `iriencode` and `urlencode` two filters for URL encoding, although they have similar purposes, there are obvious differences in application scenarios and encoding strategies.Understanding these differences can help us control the URL structure more accurately when building websites, ensuring the robustness and friendliness of the links.

2025-11-09

When is it necessary to manually use `urlencode` or `iriencode` to escape URL parameters in AnQiCMS?

AnQiCMS with its high efficiency and customizable features, provides powerful content management capabilities for website operators.In daily content publishing and site maintenance, AnQiCMS excels especially in URL structure optimization, such as through pseudo-static configuration and automatically generating `url_token` to enhance SEO effects.However, even such an intelligent system, in certain specific scenarios, we still need to manually intervene in the escaping of URL parameters to ensure the correctness, functionality stability, and website security of the link.### AnQiCMS

2025-11-09