How to implement pagination display of article lists in AnQiCMS and customize the style and logic of pagination navigation?

Calendar 👁️ 79

AnQiCMS as an efficient and flexible content management system provides intuitive and powerful functions in handling article lists and pagination display, making the content presentation meet user needs and satisfy various custom scenarios.If you are using AnQiCMS to build a website and want to implement pagination for the article list, and refine the style and logic of the pagination navigation, the following content will detail the implementation method.

Core feature:联动 of article lists and pagination tags

In AnQiCMS, the pagination display of the article list mainly depends on the close collaboration of two core template tags:archiveListwhich is used to obtain article data, whilepaginationis responsible for generating the pagination navigation.

Get article list:archiveListTag

archiveListTags are a powerful tool in AnQiCMS used to retrieve various documents (including articles, products, and custom model content). To implement pagination display, you need toarchiveListlabel'stypeThe parameter is explicitly set topage. This will inform the system that you expect it to return the data required for pagination, rather than just a fixed number of list items.

In configurationarchiveListAt the moment, some commonly used parameters can help you accurately control the logic of fetching articles:

  • moduleId: Specify which content model's article list you want to fetch, such as article model (moduleId="1") or product model, etc.
  • categoryIdGet articles by category ID.You can specify a single category ID, or separate multiple IDs with a comma.categoryId="0".
  • limitThis determines the number of articles displayed per page, for examplelimit="10"It indicates that 10 articles are displayed per page.
  • orderThis controls the sorting method of the articles, for example, sorted by the latest release time (order="id desc") Or sort by view count (order="views desc").
  • q: Used for search functionality, whentypeWithpagethen,qThe parameters are automatically read from the URL to fetch the search keywords, thus achieving pagination of search results.

An example of a basic article list retrieval, without pagination navigation, it would look like this:

{# 假设我们正在获取文章模型下的文章列表,每页显示10篇 #}
{% archiveList archives with type="page" moduleId="1" limit="10" order="id desc" %}
    {% for item in archives %}
    <li>
        <a href="{{ item.Link }}">
            <h3>{{ item.Title }}</h3>
            <p>{{ item.Description|truncatechars:100 }}</p>
            <div>
                <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>浏览量:{{ item.Views }}</span>
            </div>
        </a>
    </li>
    {% empty %}
    <li>暂无相关文章。</li>
    {% endfor %}
{% endarchiveList %}

Building pagination navigation:paginationTag

paginationThe tag is a dedicated tool used by AnQiCMS for generating pagination navigation. It handles complex page number calculations and link generation logic, you just need to call it in the template and pass byarchiveListTag (set as)type="page"when generated)pagesvariables only.

paginationThe tag itself supports relatively few parameters, but its internalpagesvariables contain rich pagination information:

  • show: Control the maximum number of page buttons displayed in pagination navigation, for exampleshow="5"It will display the maximum of 5 page numbers around the current page.
  • pages.TotalItems: Total number of articles.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: The current page number.
  • pages.FirstPage/pages.LastPage/pages.PrevPage/pages.NextPageThese objects represent the links to the home page, last page, previous page, and next page, includingName(link text) andLink(link address), as well asIsCurrent(whether it is the current page).
  • pages.PagesAn array containing a list of middle page numbers, each element is also an object, includingName/LinkandIsCurrent.

A basic pagination navigation generation example, which generates page number links:

<div class="pagination">
    {% pagination pages with show="5" %}
        <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 %}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>
    {% endpagination %}
</div>

Combine and customize: Implement complete article list pagination

toarchiveListandpaginationThese tags combined with HTML structure and CSS style can realize a complete and customizable pagination function for an article list. Usually, this code is placed in your list template file (such asarchive/list.html).

Here is a complete example of combining an article list with pagination navigation, showing how to organize HTML structure and utilizeIsCurrentproperties to highlight the current page:

`twig

<ul class="article-items">
    {# 使用 archiveList 获取文章数据,并指定为分页类型 #}
    {% archiveList archives with type="page" moduleId="1" limit="10" order="id desc" %}
        {% for item in archives %}
        <li class="article-item">
            <a href="{{ item.Link }}" class="article-link">
                {% if item.Thumb %}<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">{% endif %}
                <div class="article-info">
                    <h3 class="article-title">{{ item.Title }}</h3>
                    <p class="article-description">{{ item.Description|truncatechars:150 }}</p>
                    <div class="article-meta">
                        <span class="category">分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        <span class="date">发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                        <span class="views">浏览量:{{ item.Views }}</span>
                    </div>
                </div>
            </a>
        </li>
        {% empty %}
        <li class="no-content">很抱歉,当前分类或搜索条件下暂无文章内容。</li>
        {% endfor %}
    {% endarchiveList %}
</ul>

{# 分页导航区域 #}
<nav class="pagination-nav">
    {% pagination pages with show="7" %} {# 设置最多显示 7 个页码按钮 #}
        <ul class="pagination-list">
            {# 显示总页数和总条目数,方便用户了解列表规模 #}
            <li class="page-info">共 {{ pages.TotalPages }} 页 / {{ pages.TotalItems }} 条</li>

            {# 首页链接,如果当前是首页则添加 active 类 #}
            <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.FirstPage.Link }}" class="page-link">{{ pages.FirstPage.Name }}</a>
            </li>
            {# 上一页链接,仅当存在上一页时显示 #}
            {% if pages.PrevPage %}
            <li class="page-item">
                <a href="{{ pages.PrevPage.Link }}" class="page-link">{{ pages.PrevPage.Name }}</a>
            </li>
            {% endif %}
            {# 中间页码链接,遍历 pages.Pages 数组 #}

Related articles

How to display an article list on the front end and support filtering by content model, category, recommendation attributes, and other conditions?

AnQi CMS provides extremely high flexibility for website content, whether it is displaying articles, products, or other custom content, it can easily cope with it.When we need to display a content list on the website frontend and allow users to filter based on content models, categories, recommended attributes, and other conditions, Anqicms provides very intuitive and powerful template tags to achieve these functions. Flexible customization of list display, which not only improves user experience but also effectively helps visitors quickly find the information they are interested in.In AnQi CMS

2025-11-08

How AnQiCMS content model custom fields can be flexibly called and displayed in the front-end template?

In AnQiCMS, the custom field of the content model has brought great flexibility to our website content management, allowing us to add unique attributes to content types such as articles, products, and events according to different business needs.But it is not enough to create these fields in the background. How to flexibly present them on the website front-end, so that visitors can see this customized information, is the key to content operation.Next, we will delve into how the AnQiCMS content model custom fields can be flexibly called and displayed in the front-end template, helping you make full use of this powerful feature.###

2025-11-08

How to set up a Banner image and thumbnail for a category page and display it as a carousel or list on the frontend?

In website operation, adding attractive visual elements to category pages, such as banner images and thumbnails, is an important step to improve user experience and website professionalism.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that fully considers these needs, allowing you to easily set up and display these images on category pages.This article will guide you on how to configure Banner images and thumbnails for category pages on the AnQi CMS backend, and share practical methods for displaying them as a carousel or list in the website frontend template.--- ### Step 1

2025-11-08

How to customize SEO title, keywords, description, and URL display on the category page to optimize the performance of the category page?

In website operation, category pages play a vital role, they are not only the key entry points for users to browse content and explore the website structure, but also the core nodes for search engines to understand the website theme and allocate weight.Effectively optimize the SEO performance of the category page, which can significantly improve the overall visibility and user experience of the website.AnQiCMS (AnQiCMS) provides powerful and flexible tools for users, allowing for detailed customization and optimization of SEO titles, keywords, descriptions, and URL structures on category pages.

2025-11-08

How does image resource management in AnQiCMS affect the display quality and loading speed of front-end images?

In the process of running a website, images play a crucial role.They are not only part of the content presentation, but also a key factor affecting user experience and website performance.AnQiCMS (AnQiCMS) provides a series of practical functions in image resource management, which are directly related to the display quality and loading speed of the pictures on our website's front end.Deeply understand and make good use of these tools, which can help us build a website that is both beautiful and efficient.Why is image management crucial for a website?

2025-11-08

How to configure independent templates, SEO information, and content display for single pages (such as "About Us", "Contact Us")?

When operating a website, some seemingly simple single pages, such as 'About Us', 'Contact Us', or 'Terms of Service', carry the brand image, trust endorsement, and user conversion entry of the website.Independently design a visual style for these pages, optimize their search engine (SEO) information, and flexibly display content, which is crucial for enhancing user experience and the professionalism of the website.AnQiCMS provides powerful and flexible features that allow you to easily meet these needs.### Core Function: Customize Exclusive Experience for Single Page First, let's understand how to use AnQiCMS

2025-11-08

How to set and display the global contact information (phone, address, email, social media, etc.) of AnQiCMS?

In website operation, clear and convenient contact information is the key to building trust and promoting communication.Whether it is a phone number, address, email, or increasingly important social media channels, this information needs to be prominently and consistently displayed on your website.AnQiCMS knows this, therefore it provides a直观且集中的 way to manage the global contact information of the website, allowing your visitors to easily find you wherever and whenever.

2025-11-08

How to customize the website navigation menu and control its display order and level relationship at different positions on the website?

The website navigation is a map for users to browse the website, not only guiding users to find the information they need, but also reflecting the structure of the website and the user experience.In AnQi CMS, customizing and managing the navigation menu of a website, including their display order and hierarchical relationships, is an operation that is flexible and efficient.In order to optimize the user experience, or to better support content marketing and SEO strategies, Anqi CMS provides powerful and intuitive tools.Next, we will explore how to customize your website navigation in Anqi CMS in detail.

2025-11-08