How to implement the pagination display function of the article list in AnQiCMS?

Calendar 👁️ 70

The pagination feature of the article list is crucial for any content management system, as it not only enhances the user browsing experience and avoids the slow loading caused by long content on a single page, but also helps search engines better crawl and index the website content.In AnQiCMS, implementing this feature is both flexible and efficient, thanks to its simple template tag design.

Next, we will together learn how to easily implement pagination for article lists in AnQiCMS.

The core component of the pagination feature in AnQiCMS.

In the AnQiCMS template system, pagination display mainly relies on two key template tags:archiveListandpagination. They work together,archiveListresponsible for fetching and preparing the article data needed for pagination, whilepaginationthen generate and render clickable pagination navigation based on these data.

specific steps to implement article list pagination

First step: usearchiveListTag to get pagination data

Firstly, you need to use in the template file displaying the article list (usuallyarticle/list.htmlor customized according to the categoryarticle/list-ID.htmletc), usingarchiveListLabel to get article data. To enable pagination, you need totypethe parameter to"page"and specify the number of articles to display per page, for examplelimit="10"means 10 articles per page.

This tag intelligently identifies whether the current page contains classification ID, model ID, or search keywords, and filters out the corresponding articles accordingly.For example, if you use this tag on a category page, it will automatically retrieve the articles under that category; if on the search results page, it will filter according to the search keywords.

You can use it like thisarchiveListTags:

{% archiveList articles with type="page" limit="10" moduleId="1" categoryId="0" %}
    {# 循环遍历当前页的文章数据 #}
    {% for item in articles %}
        {# 这里是每篇文章的显示结构,例如标题、简介、发布日期等 #}
        <div class="article-item">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>{{ item.Description|truncatechars:150 }}</p> {# 截取前150字作为简介 #}
            <div class="meta-info">
                <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>浏览量:{{ item.Views }}</span>
            </div>
            {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
            {% endif %}
        </div>
    {% empty %}
        {# 如果没有文章,显示此内容 #}
        <p>当前列表暂无文章。</p>
    {% endfor %}
{% endarchiveList %}

In the code above,articlesIt is a variable name that contains all the article data on the current page.moduleId="1"It is usually used to specify the article model (AnQiCMS default article model ID is 1),categoryId="0"Indicates that the parent category is not limited, if omitted, it will automatically match the articles of the current category.for item in articlesIt will cycle through these articles.{% empty %}It is a very practical syntax, whenarticlesThe list will be automatically displayed when it is empty{% empty %}and{% endfor %}The content between.

Second step: usepaginationThe label renders pagination navigation

InarchiveListAfter the label, you can usepaginationThe label to generate and display pagination navigation. This label will be based onarchiveListThe pagination information has been processed, automatically creating a pagination structure including the home page, previous page, next page, last page, and middle page number links.

paginationTags provide ashowThe parameter is used to control how many numeric page number links are displayed in the pagination navigation, for exampleshow="5"Displays the maximum of 5 page numbers around the current page.

The followingpaginationDetailed usage example of the tag:

`twig

{% pagination pages with show="5" %}
    {# 首先,您可以显示一些总体信息,例如总文章数、总页数和当前页码 #}
    <p>共 {{ pages.TotalItems }} 篇文章,{{ pages.TotalPages }} 页,当前第 {{ pages.CurrentPage }} 页。</p>

    <div class="page-links">
        {# 首页链接,通过 pages.FirstPage 获取 #}
        <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{ pages.FirstPage.Link }}">首页</a>

        {# 上一页链接,仅当存在上一页时显示 #}
        {% if pages.PrevPage %}
            <a class="page-link" href="{{ pages.PrevPage.Link }}">上一页</a>
        {% endif %}

        {# 中间页码链接,这是通过 pages.Pages 数组循环生成的 #}
        {% for page in pages.Pages %}
            <a class="page-link {% if page.IsCurrent %}active{% endif %}" href="{{ page.Link }}">{{ page.Name }}</a>
        {% endfor %}

        {# 下一页链接,仅当存在下一页时显示 #}
        {% if pages.NextPage %}
            <a class="page-link" href="{{ pages.NextPage.Link }}">下一页</a>
        {% endif %}

        {# 尾页链接,通过 pages.LastPage 获取 #}
        <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{ pages.LastPage.Link }}">尾页</a>

Related articles

How to display the viewing volume of articles or products on the frontend page?

Bring content to life: easily display the number of views for articles or products on the Anqi CMS front-end page In website operations, the number of views for articles or products is often an important indicator of how popular the content is.It not only provides visitors with an intuitive reference, forming a "social identity" effect, guiding them to discover popular content, but also helps operators quickly identify high-value content.AnQi CMS is an efficient content management system that fully considers the actual needs of users, making it very simple and intuitive to display the number of views of articles or products on the front-end page.

2025-11-08

How to set a default thumbnail to automatically display when there is no image in the article?

In content operation, images play a crucial role.They can not only catch the visitor's eye, enhance reading interest, but also effectively convey information and enhance the brand image.However, when updating articles daily, we may occasionally forget to upload thumbnails, or some content is not suitable for pictures.This is when a blank page appears on the article list or detail page, which seems unprofessional and affects user experience.Fortunately, AnQiCMS (AnQiCMS) has considered this point and provided a very practical feature: setting a default thumbnail.With it, even if the article does not have a picture

2025-11-08

What thumbnail processing methods does AnQiCMS support, and how to set them to optimize the display effect?

In website operation, image content plays a crucial role, especially exquisite thumbnails can quickly attract users' attention, enhance the visual beauty of the page, and improve the click-through rate.AnQiCMS (AnQiCMS) offers flexible and diverse functions in image processing, especially for thumbnail generation and optimization, aiming to help websites achieve **display effects.We will delve into the thumbnail processing methods supported by AnQiCMS, as well as how to make your website images come to life through reasonable settings.### The core mechanism of AnQiCMS thumbnail processing First

2025-11-08

How to dynamically display the 'recommended properties' (such as headlines, recommendations) of articles or products on a page?

When operating website content, we often need to make special recommendations for certain articles or products, such as 'headline', 'hot', or 'recommended', etc., in order to display them more prominently on the page and guide users' attention.AnQiCMS provides a very flexible "recommendation attribute" feature, allowing you to easily achieve this.Let's take a look together at how to set these properties in AnQiCMS and dynamically display them on your website.

2025-11-08

How to sort the list display according to the creation time or view count of the articles?

In website content operation, the presentation sequence of content is crucial for user experience and information delivery efficiency.Whether it is a news portal, technology blog, or product showcase website, reasonably adjusting the sorting method of the content list according to different operational goals can significantly enhance the vitality and attractiveness of the website.AnQiCMS (AnQiCMS) is well-versed in this, providing intuitive and powerful features that allow us to easily sort the content list by the creation time or number of views.###

2025-11-08

How to display 'Previous article' and 'Next article' links on the article detail page?

In website content operation, optimizing the reading experience of users has always been one of our core goals.When immersed in an excellent article, it is natural to want to smoothly switch to related or the next article without having to return to the list page to find it.This seamless navigation can not only effectively improve the user's stay time on the website, reduce the bounce rate, but also help search engines better understand the structure of the website content, thereby having a positive impact on SEO.Aqy CMS provides a very intuitive and easy-to-use solution for this

2025-11-08

How to create and display multi-level navigation menus in AnQiCMS?

In website operation, a clear and effective navigation menu is the core of user experience, which can help visitors quickly find the information they need.AnQiCMS (AnQiCMS) knows this well and provides flexible and powerful features for you to easily create and manage multi-level navigation menus, whether it is a simple two-level dropdown menu or a complex menu combined with dynamic content display, it can meet your needs. Next, we will learn together how to create and display multi-level navigation menus in AnQiCMS.### One, Back-end Management

2025-11-08

How to highlight the link of the current visited page in the navigation menu?

When a user visits your website, a clear and intuitive navigation menu can significantly enhance their browsing experience.One important optimization is to make the navigation menu intelligently highlight the current page link being visited, so that visitors can clearly know where they are on the website.AnQi CMS provides a simple and powerful way to implement this feature, without complex development, just need to configure cleverly in the template.### Understanding the navigation mechanism of Anqi CMS Anqi CMS is built with a flexible template tag system, the core of which is the "navigation list tag"

2025-11-08