How to implement pagination functionality for article or product lists in AnQiCMS templates?

Calendar 👁️ 73

How to implement pagination functionality for article or product lists in AnQiCMS templates?

For any content management system, effective management and presentation of a large amount of content are core needs.When the number of articles or products on a website increases, if there is no reasonable pagination mechanism, users may feel tired while browsing, and the website's loading speed may also be affected.AnQiCMS as an efficient content management system provides concise and powerful template tags, helping us easily implement pagination for article or product lists, thereby greatly enhancing user experience and website performance.

In AnQiCMS, implementing pagination mainly involves the coordination of two core template tags: used to obtain list data:archiveList(or similar list tags like)categoryList/tagDataList)and dedicated to generating pagination navigationpagination. Understanding their working principles and parameter settings is the key to building a smooth pagination experience.

Step one: prepare the list data——usingarchiveListTag

Firstly, we need to call the corresponding list tags in the template to retrieve the article or product data. For example, using the most common article or product list, we will usearchiveListThe tag can not only query content but also inform the AnQiCMS system that we need to paginate this content through specific parameters.

While usingarchiveListTwo key parameters are essential for implementing pagination:

  • type="page"This is the most important parameter, it explicitly tells the system that the current list needs to be displayed with pagination. If this parameter is not present,archiveListThe tag will only retrieve a specified number of list data and will not provide any pagination information.
  • limit: This parameter is used to set the number of articles or products to be displayed per page. For example,limit="10"It indicates that 10 items are displayed per page.

A basicarchiveListAn example of use might be as follows, it will retrieve the article model (assuming)moduleId="1") and paginate the content for 10 items per page:

{% archiveList archives with moduleId="1" type="page" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h3>{{item.Title}}</h3>
            <p>{{item.Description}}</p>
        </a>
    </li>
    {% empty %}
    <li>暂时没有更多内容。</li>
    {% endfor %}
{% endarchiveList %}

In this code block,archivesIt is a custom variable name that will contain all the articles or product data on the current page. ThroughforLoop througharchives, we can sequentially display the title, link, and introduction information of each item.{% empty %}A block provides a friendly prompt, displayed when there is no content.

Step 2: Insert pagination navigation - usingpaginationTag

After obtaining the list data, the next step is to generate clickable pagination navigation links. AnQiCMS providespaginationTag to complete this task. This tag can automatically identifyarchiveListGenerate pagination data and render a navigation bar including home page, previous page, next page, and specific page numbers.

paginationLabels usually need to be paired withshowparameters to control how many page number buttons are displayed on the page. For example,show="5"this means that up to 5 page number buttons are displayed.

paginationThe tag will encapsulate all pagination-related information in a variable namedpages(The variable name can be customized, but it is customary to usepages)pagesThe object contains many useful properties, such as:

  • pages.TotalItemsTotal number of items.
  • pages.TotalPagesTotal number of pages.
  • pages.CurrentPageCurrent page number.
  • pages.FirstPageInformation of the first page (including)NameandLink)
  • pages.LastPageInformation of the last page (including)NameandLink)
  • pages.PrevPage: Previous page information (includingNameandLink)
  • pages.NextPage: Next page information (includingNameandLink)
  • pages.Pages: An array containing intermediate page number information, each element also includesName(page number) andLink(link), as well asIsCurrent(Is the current page) Boolean value.

A standard pagination navigation structure example would usually look like this:

<div class="pagination-container">
    {% pagination pages with show="5" %}
    <ul class="pagination-list">
        {# 首页链接 #}
        <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>
    </ul>
    <p>当前第 {{pages.CurrentPage}} 页 / 共 {{pages.TotalPages}} 页 (总共 {{pages.TotalItems}} 条)</p>
    {% endpagination %}
</div>

By checkingIsCurrentProperties, we can add specific CSS styles for the current page number, for example,activeA class to provide visual feedback.

Step 3: Integrate into the actual template

toarchiveListandpaginationCombined together, we can integrate it into the actual template file (for example, the article category list page'sarticle/list.htmlor product list page'sproduct/list.html) Implement complete pagination functionality. Typically, list content is placed in the main area of the page, and pagination navigation is placed below the list.

<div class="content-list">
    {# 第一步:文章或产品列表内容 #}
    {% archiveList archives with moduleId="1" type="page" limit="10" %}
        {% for item in archives %}
        <div class="item">
            <a href="{{item.Link}}">
                <h2>{{item.Title}}</h2>
                <p>{{item.Description}}</p>
                <span class="meta">{{item.CreatedTime|stampToDate:"2006-01-02"}} - {{item.Views}} 浏览</span>
            </a>
        </div>
        {% empty %}
        <p class="no-content">抱歉,当前分类下还没有内容。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 第二步:分页导航 #}
    <div class="pagination-area">
        {% pagination pages with show="7" %}
        <ul class="pagination-controls">
            <li class="{% if pages.FirstPage.IsCurrent %}disabled{% endif %}">
                <a href="{{pages.FirstPage.Link}}">首页</a>
            </li>
            {% if pages.PrevPage %}
            <li>
                <a href="{{pages.PrevPage.Link}}">上一页</a>
            </li>
            {% endif %}
            {% for pageItem in pages.Pages %}
            <li class="{% if pageItem.IsCurrent %}active{% endif %}">
                <a href="{{pageItem.Link}}">{{pageItem.Name}}</a>
            </li>
            {% endfor %}
            {% if pages.NextPage %}
            <li>
                <a href="{{pages.NextPage.Link}}">下一页</a>
            </li>
            {% endif %}
            <li class="{% if pages.LastPage.IsCurrent %}disabled{% endif %}">
                <a href="{{pages.LastPage.Link}}">尾页</a>
            </li>
        </ul>
        <p class="pagination-info">当前第 {{pages.CurrentPage}} 页 / 共 {{pages.TotalPages}} 页 (总共 {{pages.TotalItems}} 条)</p>
        {% endpagination %}
    </div>
</div>

By following these steps, we not only achieved effective content display, but also provided users with convenient navigation. The pagination feature of AnQiCMS is designed very intuitively, as long as you mastertype="page"andpaginationThe usage of labels can easily handle the pagination needs of various lists.

Common questions (

Related articles

How does AnQiCMS filter and display content based on article recommendation attributes (such as headline, recommended)?

In content operation, effectively highlighting and displaying important articles is the key to improving user experience and guiding traffic.AnQiCMS (AnQiCMS) fully understands this point, therefore, it provides a flexible article recommendation feature, allowing you to mark it based on the importance of the content or specific use, and accurately filter and display it on the website front end.

2025-11-08

How to exclude content of a specific category from the article list?

In website content operation, we often encounter such needs: we hope to display most of the content on the article list page, but articles of certain specific categories are not listed here.For example, you may have a "Company Announcement" category that you only want to display on a separate page, or some articles for internal reference that you do not want to appear in the regular article list facing the public.AnQiCMS (AnQiCMS) provides a very flexible and intuitive way to handle this situation, allowing you to accurately control the display of content on the front end.The Anqi CMS through its powerful template tag system

2025-11-08

How to set the number of articles or products displayed per page in AnQiCMS?

In website operation, especially when managing pages that require a large amount of content display, such as article lists and product display pages, how to efficiently control the number of items displayed per page directly affects user experience and page loading speed.AnQiCMS provides a flexible and powerful mechanism to meet this requirement, it allows you to customize the display of each page according to different page and content types through fine-grained control at the template tag level.The Anqi CMS can provide this flexibility because it closely integrates the display logic of the list content with the template design

2025-11-08

How to display the list of articles by category in AnQiCMS?

It is crucial to organize and display information efficiently in website content management.For users, being able to clearly browse article lists by different categories greatly enhances the access experience and also helps search engines better understand the website structure, thereby optimizing SEO effects.AnQiCMS (AnQiCMS) provides us with flexible and powerful tools, making this requirement easily accessible.

2025-11-08

How does AnQiCMS allow search results to be paginated on the page?

In AnQiCMS, implementing pagination for the website's search results is an important function for improving user experience and optimizing the website structure.AnQiCMS's powerful template tag system makes this process intuitive and efficient.By reasonably utilizing the `archiveList` and `pagination` core tags, you can easily build a functional search results page.

2025-11-08

How can articles be sorted by views in the AnQiCMS template?

In AnQiCMS, content management is not limited to publishing and organizing, how to effectively display these contents, especially placing popular articles in prominent positions, is the key to improving user experience and website activity.This article will introduce in detail how to sort the article list by views in the AnQiCMS template, making hot content naturally stand out.

2025-11-08

How to display a list of articles published by a specific author in AnQiCMS?

In AnQiCMS, efficiently managing and displaying content is the core of website operation.Sometimes, you may need to display all the articles published by a specific author, such as creating an author column, a team member introduction page, or a personal portfolio.AnQiCMS's powerful template tag system provides a flexible way to meet this requirement, allowing you to easily filter and display a list of content from specific authors.This article will introduce you to how to display a list of articles published by a specific author in AnQiCMS, helping you better organize your website content.##

2025-11-08

How to filter and display a list of documents in AnQiCMS using custom parameters?

In AnQiCMS (AnQiCMS), when managing and displaying a large amount of content, we often need to go beyond simple categories and tags to achieve more refined content filtering.For example, a real estate website may need to filter listings by "type", "area", and "price range";An e-commerce website may need to filter products by color, size, and brand.AnQiCMS provides a powerful custom parameter feature, making it very intuitive and efficient to implement this advanced filtering.Below, we will gradually understand how to use AnQiCMS

2025-11-08