How to implement pagination for article lists and limit the number of items per page?

Calendar 👁️ 73

In website operation, especially when managing a large amount of content, the pagination display of the article list is an indispensable function.It not only makes it easier for users to browse content, avoids the problem of too much data loading on a single page and slowing down the speed, but also improves the overall user experience and SEO friendliness of the website.In AnQi CMS, implementing the pagination display of article lists and flexible control of the number of items per page is very intuitive.

Next, we will explore how to implement pagination in the Anqi CMS template and limit the number of articles displayed per page.


Efficient content management: Implementing article list pagination

AnQi CMS provides powerful template tag features, among whicharchiveListTags are used to retrieve lists of articles (or other content models). To implement pagination, we first need to tellarchiveListLabel, we want a paginated list, not a simple fixed quantity list.

This can be done byarchiveListSet in the labeltype="page"Implement the parameters. For example, on a category list page (usually corresponding to the template directory){模型table}/list.htmlfile), you can retrieve the article list in the following way:

{% archiveList archives with type="page" %}
    {% for item in archives %}
        <div class="article-item">
            <h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
            <p>{{item.Description}}</p>
            <div class="meta-info">
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </div>
    {% empty %}
        <p>该分类下暂时没有文章。</p>
    {% endfor %}
{% endarchiveList %}

In this code block,archivesThis is the variable name defined, used to store the article list data obtained.type="page"The parameter informs the system that this list needs to support pagination.for item in archivesThen iterate over each article and display its title, description, publication date, and reading volume information.emptyTags are a very practical feature, which displays alternative content when the list is empty, preventing the page from being blank.

Fine control: limit the number of articles per page.

Whentype="page"After enabling the pagination feature, we still need a parameter to control the number of articles displayed per page, which islimitParameter.limitThe parameter allows you to set an integer value to precisely define the number of articles displayed per page.

For example, if you want to display 10 articles per page, you canarchiveListthe tag withlimit="10":

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <div class="article-item">
            <h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
            <p>{{item.Description}}</p>
            <div class="meta-info">
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </div>
    {% empty %}
        <p>该分类下暂时没有文章。</p>
    {% endfor %}
{% endarchiveList %}

By adjustinglimitThe value, you can easily control the density of the content on each page to adapt to different design styles or user reading habits.For example, a blog post list may want to display more per page (such as 15-20 articles), while a product display list may need fewer items to highlight the details of each product (such as 6-8 items).

Navigation and User Experience: Implement Pagination Control

Just displaying the list of articles and limiting the number is not enough; users also need an intuitive pagination navigation to switch pages. Anqi CMS provides specialpaginationLabel. This label can automatically match the current URL andarchiveListGenerated pagination information, rendering complete 'Home', 'Previous page', 'Next page', 'End page' and page number links in the middle.

paginationTags are usually witharchiveListLabels should be used together, and a variable name needs to be defined to receive pagination data, for examplepagesOne of the commonly used parameters isshowIt can control the maximum number of page number buttons displayed in the middle page area.

Here is a complete pagination navigation code example:

<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>
        <div class="pagination-info">
            总共 <b>{{pages.TotalItems}}</b> 篇文章,当前第 <b>{{pages.CurrentPage}}</b> 页 / 共 <b>{{pages.TotalPages}}</b> 页
        </div>
    {% endpagination %}
</div>

In the above code,pagesThe variable contains all information related to pagination, such aspages.FirstPage.LinkGet the link to the home page,pages.CurrentPageindicating the current page number.IsCurrentThe attribute is a very convenient boolean value, which returnstruewhen a certain page number is the current page, allowing you to add it via CSS.activeHighlight the current page number to enhance user experience.

Comprehensive practice: complete pagination code for article list

toarchiveListandpaginationCombine the tags and you can implement a fully functional and easy-to-manage article list pagination in AnQi CMS. Usually, this code is placed in the template of your website.{模型table}/list.htmlFor example, inside the filearticle/list.html.

Here is an integrated example:

`twig {# Assuming this is the template file for the article category list page, such as: /template/default/article/list.html #}

{% extends 'bash.html' %} {# Inherit basic layout file #}

{% block content %}

<h1 class="mb-4">
    {% categoryDetail with name="Title" %}
</h1>

<div class="article-list-wrapper">
    {% archiveList archives with type="page" limit="10" %} {# 获取分页文章列表,每页10篇 #}
        {% for item in archives %}
        <div class="card mb-3">
            <div class="card-body">
                <h5 class="card-title">
                    <a href="{{item.Link}}">{{item.Title}}</a>
                </h5>
                <p class="card-text">{{item.Description}}</p>
                <p class="card-text-sm text-muted">
                    <small>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</small>
                    <small class="ms-3">阅读量:{{item.Views}}</small>
                </p>
            </div>
        </div>
        {% empty %}
        <div class="alert alert-info" role="alert">
            该分类下暂时没有文章。
        </div>
        {% endfor %}
    {% endarchiveList %}
</div>

{# 分页导航区域 #}
<nav aria-label="Page navigation" class="mt-4">
    {% pagination pages with show="5" %} {# 显示5个页码按钮 #}
        <ul class="pagination justify-content-center">
            <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a class="page-link" href="{{pages.FirstPage.Link}}" aria-label="首页">首页</a>
            </li>
            {% if pages.PrevPage %}
            <li class="page-item">
                <a class="page-link" href="{{pages.PrevPage.Link}}" aria-label="上一页">上一页</a>
            </li>
            {% endif %}
            {% for item in pages.Pages %}
            <li class="page-item {% if item.IsCurrent %}active{% endif %}">
                <a class="page-link" href="{{item.Link}}">{{item.Name}}</a>
            </li>
            {% endfor %}
            {% if pages.NextPage %}
            <li class="page-item">
                <a class="page-link" href="{{pages.NextPage.Link}}" aria-label="下一页">下一页</a>
            </li>
            {% endif %}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a class="page-link" href="{{pages.Last

Related articles

How to filter tags through document parameters to achieve a combination display of list content with multiple conditions?

In content operation, we often need to display lists of content with different themes and properties, and allow visitors to filter according to their own needs. For example, a real estate website may need to filter listings by "house type", "location", "area range", and other multi-dimensional combinations.If each time is organized manually or developed custom, it is not only inefficient but also difficult to maintain.AnQiCMS (AnQiCMS) provides a flexible and powerful document parameter filtering mechanism that can help us easily achieve this combination display of list content with multiple conditions. Next

2025-11-08

How to display associated categories and tags lists on the article detail page?

When managing website content in AnQi CMS, the article detail page is the core page for users to obtain information.In addition to the content of the article itself, displaying the category information and related tag list of the article to the visitor can greatly improve the user experience, help visitors quickly understand the context of the article, and effectively enhance the internal link structure of the website, which is greatly beneficial for search engine optimization (SEO).Next, we will discuss how to flexibly display these related information on the article detail page of Anqi CMS.AnQi CMS uses an intuitive and powerful template tag system

2025-11-08

How to format the timestamp of an article into a readable date and time format for display?

In website content operation, the time of article publication or update is an important element in conveying information to visitors.A clear and readable date and time format not only improves user experience but also allows visitors to quickly understand the timeliness of the content.AnQi CMS provides a very practical template tag to help us easily achieve this goal.### Core Tool: `stampToDate` Tag Anqi CMS allows us to use the `stampToDate` tag

2025-11-08

How to call the cover main image, thumbnail, and group image to enrich the display effect?

In website operation, images are indispensable elements to attract visitors and convey information.Reasonably using the cover image, thumbnail, and group image of the article can greatly enhance the visual appeal of the website, enrich the form of content presentation, and make your content more vivid and attractive.AnQiCMS as a flexible and efficient content management system provides an intuitive way to manage and call these image resources, helping you easily achieve diverse image display effects.Understanding the image types in AnQiCMS

2025-11-08

How to display related documents or search results on the article list page?

In website operation, how to make visitors find the content they are interested in faster, or seamlessly discover more related information after browsing an article, is the key to improving user experience and website stickiness.AnQiCMS (AnQiCMS) provides powerful and flexible template tags that can help us easily implement displaying related documents or search results on the article list page, thus building a more intelligent and interactive website.### Smartly using content list tags to present dynamic information One of the core advantages of AnQi CMS lies in its highly customizable template system

2025-11-08

How to get and display the custom parameters of a specified document (such as author, source)?

When using AnQi CMS to manage your website content, you may find that relying solely on default fields such as title, content, and summary is not enough to fully meet the needs of personalized display.For example, you may wish to display 'author' and 'source' information on the article detail page, or show 'material' and 'size' and other specific parameters on the product page.The AnQi CMS provides powerful custom parameter features, allowing you to easily add, manage, and display these personalized information for different types of documents (such as articles, products).This article will provide a detailed introduction on how to obtain and display custom parameters of specified documents in AnQi CMS

2025-11-08

How to get and display the list of all documents associated with a specified Tag?

Manage content in AnQi CMS, besides organizing through categories, flexibly using the "Tag" feature is also the key to improving the aggregation ability of website content and user experience.Tags can connect documents of different categories, different models, but with the same theme, providing visitors with more ways to discover content.How can we specifically retrieve and display the list of all documents associated with the specified tags?Next, we will delve deeper into this practical skill. ### Understanding the Tag System of AnQi CMS The tag design of AnQi CMS is very flexible, it does not depend on any specific category or model

2025-11-08

How to retrieve and display the list of friend links of a website?

In website operation, friendship links play an important role in connecting each other, promoting traffic, and improving search engine rankings.A well-maintained, clear display of the friendship link area, which not only reflects the openness of the website, but also provides users with more valuable jump paths.AnQiCMS provides users with a convenient friend link management feature, allowing you to easily obtain and display these links on your website. ### Manage your friend links: Backend settings Before starting the front-end display, we need to make sure that the friend links have already been configured in the Anqi CMS backend. Usually

2025-11-08