How to implement pagination functionality in Anqi CMS and customize the display style of page numbers?

Calendar 👁️ 65

In AnQi CMS, the pagination feature of website content is an indispensable part of improving user experience and optimizing the site structure.Whether it is a blog article list, product display page, or other dynamic content, reasonable pagination can make it easier for users to browse a large amount of information, and it can also help search engines better understand and crawl website content.Today, let's delve deeper into how to implement pagination functionality in AnQiCMS and customize the display style of page numbers according to your needs.

Why do we need pagination?

Imagine that your website has hundreds or thousands of excellent articles.If there is no pagination, all articles will pile up on one page, not only will it load slowly, but users will also find it difficult to find the content they are interested in, and they will leave quickly.The purpose of pagination is to divide the content into multiple smaller pages, making page loading faster, navigation clearer, and the user experience naturally better.At the same time, a clear pagination structure is also helpful for search engines to understand the hierarchy of website content, improving the efficiency of inclusion.

How to implement pagination in AnQiCMS

AnQiCMS provides a set of intuitive and flexible template tags to handle content lists and pagination display. The core lies in the cooperation of two tags:Content list tag(such asarchiveList), andPagination Label(pagination)

Step 1: Prepare the content list that needs pagination

In your template file (for examplelist.htmlorindex.html),Firstly, you need to use the content list tag to get the paginated content. Here, we take the example of getting the article list, usingarchiveListtag. The key is to settype="page"Parameters, this will tell AnQiCMS to prepare pagination data for this list. At the same time, throughlimitParameters can be used to control how many items are displayed per page.

A typical way to get a content list may be as follows:

{# 假设我们正在获取ID为1的文章分类下的内容,每页显示10条 #}
{% archiveList archives with categoryId="1" type="page" limit="10" %}
    <div class="article-list">
        {% for item in archives %}
        <div class="article-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
            <div class="meta">
                <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>阅读量:{{item.Views}}</span>
            </div>
        </div>
        {% empty %}
        <p>抱歉,目前该分类下没有任何文章。</p>
        {% endfor %}
    </div>
{% endarchiveList %}

In the code above,archivesIt is the variable we define, which contains all the article data on the current page.type="page"It is the key to enabling pagination,limit="10"which specifies displaying 10 articles per page.

Step two: Insert pagination tags and understand the variables they provide

Below the content list, use them immediatelypaginationTags to render pagination navigation. This tag will be based on the previousarchiveListGenerated pagination data, automatically outputs page number information.

<div class="pagination-container">
    {% pagination pages with show="5" %}
        {# 在这里构建您的分页样式 #}
    {% endpagination %}
</div>

HerepagesIt is also a custom variable name, it contains all the data related to pagination.show="5"This parameter indicates that up to 5 page number buttons are displayed before and after the current page, making the pagination navigation look cleaner.

pagesVariables provide rich data, allowing you to flexibly customize the pagination style:

  • pages.TotalItems: Total number of items.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPageCurrent page number.
  • pages.FirstPage: Home object, includingName(such as 'Home' or '1'),Link(link address) andIsCurrent(whether it is the current page).
  • pages.LastPage: End page object, structure andFirstPageSimilar.
  • pages.PrevPage: The previous page object, structure andFirstPagesimilar, if it is the first page, it is empty.
  • pages.NextPage: The next page object, structure andFirstPagesimilar, if it is the last page, it is empty.
  • pages.Pages: An array that contains the middle page number list, each element is an object, similarly containingName(page number),LinkandIsCurrent.

Step 3: Customize the page number display style

NowpagesThese data provided by the variable allow you to build any pagination style you want using HTML and CSS. Usually, we would useforLoop throughpages.Pagesto display the middle page numbers and combineifThe statement to determine the status of the current page, first page, last page, previous page, and next page, and add different CSS classes.

Here is a commonly used pagination style code example, you can modify the HTML structure and CSS class names according to your website design.

{# 假设我们已经通过 archiveList 获取了内容,现在开始渲染分页 #}
<div class="pagination-wrapper">
    {% pagination pages with show="5" %}
    <ul class="pagination">
        {# 显示总页数和当前页码信息,这部分您可以选择显示或隐藏 #}
        <li class="info">总数:{{pages.TotalItems}}条,共{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>

        {# 首页链接 #}
        <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 %}

        {# 中间页码列表 #}
        {% for item in pages.Pages %}
        <li class="page-item {% if item.IsCurrent %}active{% endif %}">
            <a href="{{item.Link}}" class="page-link">{{item.Name}}</a>
        </li>
        {% endfor %}

        {# 下一页链接 #}
        {% if pages.NextPage %}
        <li class="page-item">
            <a href="{{pages.NextPage.Link}}" class="page-link">{{pages.NextPage.Name}}</a>
        </li>
        {% endif %}

        {# 末页链接 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
            <a href="{{pages.LastPage.Link}}" class="page-link">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
    {% endpagination %}
</div>

By usinglioratagsactive/disabledClasses, you can then use in your stylesheet (for examplepublic/static/css/style.cssDefine their visual representation, such as changing the background color, font color, etc., to achieve a pagination style that fully conforms to your website's style.

Comprehensive example: article list and pagination

Combining the above two parts, the pagination function of a complete article list page is implemented.

``twig <!DOCTYPE html>

<meta charset="UTF-8">
<title>{% tdk with name="Title" siteName=true %}</title>
<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
<style>
    /* 简单的分页样式示例,您可以根据需要进行扩展和修改 */
    .pagination-wrapper {
        margin-top: 30px;
        text-align: center;
    }
    .pagination {
        display: inline-block;
        padding-left: 0;
        margin: 20px 0;
        border-radius: 4px;
    }
    .pagination > li {

Related articles

How to correctly render Markdown content as HTML and display mathematical formulas or flowcharts in Anqi CMS?

In AnQi CMS, using Markdown format to write content not only improves editing efficiency, but also maintains the structuralization and readability of the content.When content involves complex mathematical formulas or a clear flowchart needs to be displayed, the strength of Markdown becomes evident.Our company provides good support for this, let's take a look at how to correctly render and display these advanced contents on the website.### Step 1: Enable Markdown Editor First, make sure that your CMS system has enabled the Markdown editor feature

2025-11-09

How does AnQi CMS truncate long text content and add an ellipsis?

In website content operation, effectively displaying information while maintaining the page's cleanliness and the smoothness of user experience is a crucial link.Especially for long text content, how to truncate the display on the list page or overview section with an ellipsis is a common technique to improve the readability and aesthetics of the website.AnQiCMS (AnQiCMS) is a feature-rich management system that provides a flexible mechanism to meet this requirement at the template layer.

2025-11-09

How to use the `archiveDetail` tag in AnQi CMS to display custom field content of a document?

AnQi CMS has a flexible content model design that allows users to add various custom fields to documents according to their business needs.These custom fields greatly enrich the expression of the website content, whether it is to display product specifications, event details, or additional information of articles, it can be handled with ease.How can `archiveDetail` tag be cleverly used on the document detail page to display these valuable custom field contents?### Understanding the core function of the `archiveDetail` tag In the Anqi CMS template system

2025-11-09

How to implement conditional judgment and loop traversal in the Anqi CMS template to control content display?

In Anqi CMS, templates are the core of website content presentation, they are not only responsible for the layout and style of content, but also bear the important responsibilities of displaying different content based on different conditions and cyclically presenting data lists.To make your website content more dynamic and interactive, it is particularly important to have a deep understanding of how to implement conditional judgments and loop traversals in templates.The Anqi CMS template engine uses syntax similar to Django, which allows you to quickly get started and flexibly apply it if you are familiar with web development.### Understand AnQiCMS

2025-11-09

How to use the global settings of Anqi CMS to unify the display of copyright information and contact details on the website?

In website operation, copyright statements and contact information are important components for building brand trust, providing user support, and ensuring legal compliance.AnQiCMS (AnQiCMS) fully understands the importance of this information, and therefore provides an intuitive and powerful global setting function, allowing website administrators to uniformly and conveniently control the display of these contents without frequent code modifications.Imagine if your website has hundreds of pages and you need to manually edit each page every time you update the copyright year or customer service phone number, it would be such a繁琐 and error-prone task.

2025-11-09

How to filter and display a specific list of documents based on keywords in AnQi CMS?

When using Anqi CMS to manage website content, we often need to search and display related document lists based on specific keywords.It is crucial to master the keyword filtering method, whether it is to create an in-site search results page or to display content closely related to a theme on a specific topic page.The AnQi CMS provides flexible and powerful template tag functions, making this task intuitive and efficient.### The foundation of keyword filtering: `archiveList` tag's `q`

2025-11-09

How to display the document category list at different levels in Anqi CMS and its associated documents?

How to efficiently organize and display a large amount of content in website operation is the key to improving user experience and website usability.For those who use AnQiCMS, the system provides powerful content model and template tag features, which can help us easily implement multi-level document classification lists and clearly display the associated documents under each category. Let's explore together how to build a website navigation with both hierarchy and rich content using these features in Anqi CMS.### Understand the content structure of AnQi CMS In AnQi CMS

2025-11-09

How to customize the Title and Description of Anqi CMS website to optimize search engine results display?

In today's highly competitive online environment, whether a website can stand out in search engines largely depends on its optimization of details.Among them, the page's Title (title) and Description (description) play a crucial role, as they are the 'business card' of the website presented on the search engine results page (SERP).Carefully customize these elements, which can not only help search engines better understand the page content, but also attract potential visitors to click, thereby improving the traffic and visibility of the website.AnQiCMS (AnQiCMS) as a powerful content management system

2025-11-09