In AnQiCMS, how to implement dynamic pagination on the article list page and control the number of items displayed per page?

Calendar 👁️ 73

Manage website content in Anqi CMS, the article list page is usually one of the main entry points for users to browse information.In order to provide a smoother user experience and optimize page loading performance, it is particularly important to implement dynamic pagination and flexible control over the number of items displayed per page.AnQi CMS provides powerful and easy-to-use template tags, allowing us to easily implement these features.

The cornerstone of dynamic pagination and control of items per page

In Anqi CMS, the implementation of dynamic pagination for article lists mainly depends on two core template tags:

  1. archiveListTagresponsible for retrieving article data that meets the conditions from the database. By setting itstype="page"parameters, we can inform the system to generate the pagination information required for these article data. At the same time,limitThe parameter directly controls the number of articles displayed per page.
  2. paginationTag: This tag is used to determine the basis ofarchiveListGenerated pagination data, build and display the actual pagination navigation links, such as "Previous page

These tags work together to make the article list not only display data, but also dynamically load different page content according to the page number and allow users to perform page jumps intuitively.

Preparation: Understand the template structure

In Anqi CMS, the template files for the article list page are usually located in the corresponding directory of the template package you are using. According to the system convention, these files may be named{模型table}/list.htmlor more specific{模型table}/list-{分类ID}.htmlFor example, if you create a category named "news" under the article model, the list page template might bearticle/list.htmlorarticle/list-新闻分类ID.html. Understanding the location of these template files helps you accurately modify and add pagination logic.

Step 1: Get the list of article data (archiveListtags)

Firstly, we need to call the template inarchiveListLabel to retrieve article data. This label has a very flexible function, which can filter articles based on various conditions.

The key to implementing pagination lies in settingtypeparameter assignment to"page"HoweverlimitThe parameter is used to set the number of articles you want to display per page. For example, if you want to display 10 articles per page, you can set it like this:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            <span>浏览量:{{item.Views}}</span>
        </a>
    </li>
    {% empty %}
    <li>暂无文章内容。</li>
    {% endfor %}
{% endarchiveList %}

In the code above:

  • archivesIt is a custom variable name used to store the article list data obtained.
  • type="page"Explicitly inform the system that this is a pagination query, and the system will prepare the data needed for pagination at the same time.
  • limit="10"Set the number of articles displayed per page to 10. You can adjust this number as needed.
  • {% for item in archives %}Loop through and display the title, description, publication date, and view count of each article.

excepttypeandlimit,archiveListTags also support many other useful parameters, such asmoduleId(Specify Model ID),categoryId(specified category ID),order(Specify the sorting method, such asid descSorted by ID in reverse order)q筛选 based on the search keywords in the URL, etc., these parameters can all help you build a more refined list of articles.

Step two: build pagination navigation (paginationtags)

InarchiveListAfter the tag generates the pagination data, we can usepaginationthe tag to render the pagination navigation. This tag will receivearchiveListInternally generated pagination information and converted into a user-friendly link collection.

<div class="pagination-controls">
    {% pagination pages with show="5" %}
    <ul>
        <li>共计:{{pages.TotalItems}}条记录,分为:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>
        {# 首页链接 #}
        <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>

In the above code:

  • pagesIs a custom variable name used to receivepaginationTags provide our pagination object.
  • show="5"The parameter controls how many page numbers are displayed at one time in the pagination navigation (excluding "Home
  • pagesThe object contains rich pagination information, such asTotalItems(Total number of records),TotalPages(Total number of pages),CurrentPage(Current page number) and the sub-object pointing to each pagination link (FirstPage,PrevPage,NextPage,LastPage) and the page number array (Pages). By traversing these sub-objects and arrays, you can flexibly build various styles of pagination navigation.

Integration Practice: Complete Code Example

Combining the above two tags, an article list page with dynamic pagination and control over the number of items per page is basically completed. The complete template code is roughly as follows:

`twig {# article/list.html or other list template file #} <!DOCTYPE html>

<meta charset="UTF-8">
<title>{% tdk with name="Title" siteName=true %} - 文章列表</title>
<style>
    .article-list ul { list-style: none; padding: 0; }
    .article-list li { margin-bottom: 15px; border-bottom: 1px dashed #eee; padding-bottom: 10px; }
    .article-list li a { text-decoration: none; color: #333; display: block; }
    .article-list li h5 { font-size: 18px; margin-bottom: 5px; }
    .article-list li p { font-size: 14px; color: #666; margin-bottom: 5px; }
    .article-list li span { font-size: 12px; color: #999; margin-right: 10px; }
    .pagination-controls ul { list-style: none; padding: 0; display: flex; justify-content: center; margin-top: 20px; }
    .pagination-controls li { margin: 0 5px; }
    .pagination-controls li a { display: block; padding: 8px 12px; border: 1px solid #ddd; text-decoration: none; color: #333; border-radius: 4px; }
    .pagination-controls li.active a, .pagination-controls li a:hover { background-color: #007bff; color: #fff; border-color: #007bff; }
</style>

<div class="container">
    <h1>最新文章</h1>
    <div class="article-list">
        <ul>
            {% archiveList archives with type="page" limit="10" moduleId="1" order="id desc" %}
                {% for item in archives %}
                <li>
                    <a href="{{item.Link}}">
                        <h5>{{item.Title}}</h5>
                        <p>{{item.Description}}</p>
                        <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        <span>浏览量:{{item.Views}}</span>
                    </a>
                </li>
                {% empty %}
                <li>暂无文章内容。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>

Related articles

How to use AnQiCMS template tags to accurately control the display content of article detail pages?

The website is operational, and the article detail page is a key link for users to deeply interact with content and understand products or services.A well-designed, precise information presentation detail page, which can not only significantly improve user experience, but also effectively assist in SEO optimization.In such a flexible and efficient content management system as AnQiCMS, we can achieve fine-grained control over the content of article detail pages by ingeniously using its template tags.

2025-11-08

How does AnQiCMS handle image resource management and optimization?

In the daily operation of websites, images are not only an important part of the content, but also a key factor affecting website performance and user experience.Efficient image resource management and optimization, can significantly improve website loading speed, improve search engine rankings, and effectively protect the copyright of original content.AnQiCMS is a system born for content operation, which provides comprehensive and practical functions in image processing to help us easily meet these challenges.### A comprehensive centralized management of image resources AnQiCMS provides a centralized management platform for image resources

2025-11-08

How does AnQiCMS determine if a string or array contains a specific keyword and display content accordingly?

In website operation, we often need to dynamically adjust the display of the page based on the specific attributes or keywords of the content.For example, when the article title includes the words 'latest', we may want to add a prominent 'NEW' label; or when a product description mentions 'Free Shipping', an icon showing free shipping should be automatically displayed.AnQiCMS (AnQiCMS) provides powerful template functions and rich filters, making it easy to meet these needs.

2025-11-08

How to remove specific characters or spaces from a string in AnQiCMS template?

In website content management, string processing is inevitable and crucial.In order to maintain the beauty of the page, keep the standardization of data output, or for SEO optimization, we often need to make fine adjustments to text content, such as removing extra spaces, punctuation marks, or other specific characters.AnQiCMS provides a flexible and powerful template engine, allowing us to easily implement these string operations in front-end templates.

2025-11-08

How to customize the URL rewrite rules of AnQiCMS website to optimize search engine display effect?

In website operation, the structure of the URL (Uniform Resource Locator) plays a crucial role in search engine optimization (SEO) and user experience.A clear and meaningful URL can not only help search engines better understand the content of the page, but also enable users to have expectations of the page content before clicking, enhancing trust.AnQiCMS as a system focusing on enterprise content management, fully understands this point, and therefore provides a flexible feature for customizing pseudostatic rules.

2025-11-08

What content models does AnQiCMS support and how do they affect the front-end content display?

AnQiCMS is a major highlight in content management with its flexible content model support, which allows the website to structure and display information according to its unique business needs.Understanding how content models operate and how they affect the presentation of frontend content is the key to efficiently using AnQiCMS for website operations. ### AnQiCMS content model: Customized information blueprint The content model can be understood as the 'data structure blueprint' of various types of information on the website.

2025-11-08

How to retrieve and display all article lists under a specified category in AnQiCMS template?

When building a website with AnQiCMS, we often need to display article lists based on specific content categories, whether it is blog article categories, product categories, or news categories.This not only helps organize the content of the website, but also improves the user's browsing experience and the search engine's friendliness.AnQiCMS provides powerful and flexible template tags, making this requirement simple and intuitive.AnQiCMS's template system uses a syntax similar to the Django template engine, supported by Go language at the bottom level, ensuring the efficiency of template parsing.in the template file

2025-11-08

How to set the Title, Keywords, and Description of the homepage of AnQiCMS to improve search rankings?

In today's digital world, the visibility of a website is crucial for attracting potential customers.In order to improve a website's ranking in search engines, the Title (title), Keywords (keywords), and Description (description) on the homepage - which we often call TDK - are indispensable foundations.AnQiCMS (AnQiCMS) is a content management system designed specifically for small and medium-sized enterprises and content operation teams, fully understanding the importance of TDK and providing an intuitive and convenient way to easily optimize the search performance of your website

2025-11-08