How to implement pagination functionality and customize the number of page numbers displayed in AnQiCMS templates?

Calendar 👁️ 72

In a content management system, a valid pagination feature is crucial for enhancing user experience and the website's SEO performance.When the amount of content on a website gradually increases, organizing and displaying the content list reasonably allows visitors to browse information more easily and helps search engines better crawl and index the pages.AnQiCMS as an efficient content management system provides flexible and easy-to-use template tags, allowing you to easily implement pagination in templates and customize the display of page numbers as needed.

To implement pagination in the AnQiCMS template, it mainly involves two core steps: first, inform the system that you need to obtain a list of content that can be paginated, and second, render the pagination navigation links on the page.

First step: Get the list of content to be paginated

In your AnQiCMS template file (such as the article list pagearchive/list.htmlor custom category list pagearticle/list.html) you need to usearchiveListOr other content list tags to get articles, products, and other data. The key is that you need to settype="page"parameters to clearly tell the system that you want this list to support pagination. At the same time,limitParameters are used to define how many items are displayed per page.

For example, if you want to display 10 items per page in a list of articles, you can retrieve the data in this way:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <div class="article-item">
        <a href="{{item.Link}}">
            <h3>{{item.Title}}</h3>
            <p>{{item.Description}}</p>
            <span class="date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </a>
    </div>
    {% empty %}
    <p>抱歉,当前分类暂无文章内容。</p>
    {% endfor %}
{% endarchiveList %}

In this code block:

  • archiveListIt is used to get the tags of the document list.
  • archivesIt is a variable name defined by us, used to store the article data obtained, you canforthrough the loopitemto access the details of each article.
  • type="page"This is a key setting to enable pagination.
  • limit="10"specifies that 10 articles are displayed per page.

The second step: Add pagination navigation to the template

After obtaining the content list that supports pagination, the next step is to display the pagination navigation links at the bottom of the page or in other appropriate positions. AnQiCMS provides a specialpaginationLabel. This label will be based onarchiveListThe pagination data obtained by the label, automatically generating "Home", "Previous page", "Next page", "End page" and the page number links in the middle.

The most important thing is that you canshowParameters can be used to flexibly control the display quantity of the middle page number links. For example, if you want the pagination navigation to only display 5 page number links around the current page, you can setshowis set to5.

The following is a complete pagination navigation example code:

<div class="pagination-nav">
    {% 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 循环逐个显示 #}
        {% 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.TotalItems}} 条记录,分为 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页。</p>
    {% endpagination %}
</div>

In this code block:

  • pagesIt is a variable that contains all pagination information, it is generated bypaginationtags.
  • show="5"Specified that the middle part can display a maximum of 5 page number links, excluding the first page, previous page, next page, and last page.For example, if the current page is 10, it may display page numbers like '8 9 10 11 12'.
  • pages.FirstPage/pages.PrevPage/pages.NextPage/pages.LastPageRepresent the link objects for home page, previous page, next page and end page, they all haveLink(link address) andName(Display Name) attribute.
  • pages.Pagesis an array that contains the page number objects in the middle part, you can access them viaforLoop through them. Each page object also hasLinkandNameProperty.
  • item.IsCurrentorpages.FirstPage.IsCurrentBoolean values can be used to determine if the current page is selected, thereby addingactiveclasses or other styles for easy identification.

Integrate example: complete article list and pagination code

Combine the above two parts of code, and a basic article list page with pagination is completed.Generally, you would place the content list in one section, followed by pagination navigation.

{# 您的文章列表页模板文件 (例如: template/default/archive/list.html) #}

{# 引入公共头部文件,通常包含网站标题、SEO元信息等 #}
{% include "partial/header.html" %}

<main class="container">
    <section class="article-list">
        <h2>最新文章</h2>
        {% archiveList archives with type="page" limit="10" %}
            {% for item in archives %}
            <div class="article-item">
                <a href="{{item.Link}}">
                    <h3>{{item.Title}}</h3>
                    <p>{{item.Description}}</p>
                    <span class="date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span class="views">{{item.Views}} 阅读</span>
                </a>
            </div>
            {% empty %}
            <p>抱歉,当前分类暂无文章内容。</p>
            {% endfor %}
        {% endarchiveList %}
    </section>

    {# 分页导航区域 #}
    <nav class="pagination-nav">
        {% pagination pages with show="7" %} {# 这里我们自定义显示7个页码链接 #}
        <ul class="pagination-ul">
            <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a href="{{pages.FirstPage.Link}}" title="首页">{{pages.FirstPage.Name}}</a>
            </li>
            {% if pages.PrevPage %}
            <li class="page-item">
                <a href="{{pages.PrevPage.Link}}" title="上一页">{{pages.PrevPage.Name}}</a>
            </li>
            {% endif %}
            {% for item in pages.Pages %}
            <li class="page-item {% if item.IsCurrent %}active{% endif %}">
                <a href="{{item.Link}}" title="第{{item.Name}}页">{{item.Name}}</a>
            </li>
            {% endfor %}
            {% if pages.NextPage %}
            <li class="page-item">
                <a href="{{pages.NextPage.Link}}" title="下一页">{{pages.NextPage.Name}}</a>
            </li>
            {% endif %}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{pages.LastPage.Link}}" title="尾页">{{pages.LastPage.Name}}</a>
            </li>
        </ul>
        <p class="pagination-info">总共 {{pages.TotalItems}} 条记录,当前显示第 {{pages.CurrentPage}} / {{pages.TotalPages}} 页。</p>
        {% endpagination %}
    </nav>
</main>

{# 引入公共底部文件 #}
{% include "partial/footer.html" %}

Remember, in the above codeclass="article-item",class="pagination-nav"This is just an example, you need to beautify these elements according to your website design, making them conform to your website style.

Advanced技巧:Customize pagination URL pattern

Under certain specific requirements, you may need to control the URL structure of pagination links more finely, for example, for SEO purposes or to maintain consistency with existing URL rules. AnQiCMS'spaginationTags providedprefixThe parameter allows you to customize the pagination URL pattern.

For example, if you want the pagination links to look like/articles/page-{page}.html, you can in thepaginationSet it like this in the tag:{% pagination pages with show="5" prefix="/articles/page-{page}.html" %}.

Related articles

How to implement multi-language content switching and display on AnQiCMS websites?

Under the wave of globalization, website multilingual support has become a necessary condition for enterprises to expand into the international market.AnQiCMS as an enterprise-level content management system, fully considers this requirement and provides a set of efficient and flexible solutions to help users easily switch and display multilingual content. ### AnQiCMS implementation logic for multilingual The core strategy of AnQiCMS for switching and displaying multilingual content is based on its powerful "multi-site management" function.

2025-11-07

How to loop through and display the article tag list in AnQiCMS templates?

In Anqi CMS, article tags are not only a tool for organizing content and improving user experience, but also an important element for optimizing search engine crawling and ranking (SEO).They can help visitors quickly find relevant content and can also help search engines better understand the website structure.How can I flexibly loop through and display these article tag lists in the AnQiCMS template?This is actually simpler than you imagine, the powerful template tag system of AnQiCMS makes everything very intuitive.

2025-11-07

How to call and display data from different sites in AnQiCMS multi-site management?

AnQiCMS (AnQiCMS) as an efficient and flexible content management system, its powerful multi-site management function is undoubtedly a highlight favored by many operators.When we hold multiple brand, multiple region, or multiple theme websites, we can manage them uniformly through a system and flexibly call and display data between different sites, which will greatly improve work efficiency and content integration.How can we implement the calling and display of data between different sites in the AnQiCMS multi-site environment?### Understanding the core of multi-site data calls

2025-11-07

How to display the unique field content according to a custom content model?

AnQi CMS with its powerful content management capabilities, especially the flexible content model, makes the organization of our website content simpler than ever before.When the standard content field cannot meet specific business needs, a custom content model and its unique fields emerge.How can you accurately call and display these unique custom field contents in the website front-end template?This article will detail the mysteries revealed for you. ### 1. Understanding the content model and custom fields of AnQi CMS One of the core strengths of AnQi CMS is its highly flexible content model

2025-11-07

How does AnQiCMS ensure that uploaded images are automatically converted to WebP format to optimize loading speed?

In today's fast-paced digital world, website loading speed directly affects user experience and search engine rankings.Especially images, they are often the main culprits in slowing down website speed.Large image files not only consume more server bandwidth, but also extend the page rendering time, leading to visitor loss. 幸运的是,AnQiCMS understands this and provides us with an elegant solution through intelligent image processing: automatically converting uploaded images to WebP format to optimize website loading speed. WebP is a modern image format developed by Google

2025-11-07

How to display the contact information of the website, such as phone, address, email, in AnQiCMS templates?

The contact information of the website, like a business card, is an important channel for visitors to understand and trust the website.Whether it is to hope that customers call to consult or to make it convenient for them to communicate through email, or to guide them to the physical store, clear and accurate contact information is indispensable.In AnQiCMS, displaying this information is a very intuitive and flexible thing, which allows us to not only manage uniformly but also display at different positions on the website according to our needs.

2025-11-07

How to control specific content to be visible only to the VIP user group in AnQiCMS?

In content operation, it is a common strategy to present some high-quality content exclusively to VIP users.This can not only enhance user stickiness and promote user conversion, but it is also an important way to realize content monetization.AnQiCMS provides a complete user group management and content permission control function, allowing you to easily implement the need for specific content to be visible only to VIP user groups. ### Backend Settings: Distinguishing Users and Content To make VIP exclusive content visible, you first need to make two key configurations in the AnQiCMS backend: user group management and content permission settings.

2025-11-07

How to display a message form on the AnQiCMS website and support the display of custom fields?

Today, with the increasing importance of digital operation, the website message board is not only an important bridge for user interaction with the website, but also a key channel for collecting user feedback and understanding market demand.AnQiCMS (AnQiCMS) fully understands this need, providing flexible and powerful form display and custom field support, allowing you to easily create an interactive platform that meets business requirements. ### Step 1: Configure the custom fields of the comment form To give the comment form more personalized information collection capabilities, we need to configure it first in the Anqi CMS backend.

2025-11-07