How to implement pagination display and style control for document list using the `pagination` tag?

Calendar 👁️ 65

As a website operator who deeply understands the operation of AnQiCMS, I know the exquisite presentation of content lies in how to serve users efficiently and elegantly.For a document list page with a large amount of content, a reasonable pagination mechanism can not only improve user experience but also optimize website performance.In AnQiCMS,paginationThe tag is the core tool to achieve this goal, it allows us to flexibly control the pagination display and style of the document list.

Understand the pagination mechanism in AnQiCMS

AnQiCMS decouples the pagination logic of the content list from the content display itself, which means you first need to usearchiveListtags totype="page"the pattern to obtain the paged document data. OncearchiveListGenerated a dataset with pagination information (usually we would name itarchives, accompanied by apagesvariable to store pagination metadata),paginationThe label can take the stage, responsible for parsing these pagination metadata and rendering them as visible navigation elements.This separation design concept gives template developers a great degree of freedom, allowing for in-depth customization of the visual presentation of pagination without affecting the core data logic.

paginationBasic usage of tags

paginationThe use of tags is very intuitive, it always coordinates with a variable that stores pagination information and appears in the structure of{% pagination pages with show="5" %}...{% endpagination %}. Here,pagesis provided byarchiveListThe tag is intype="page"mode automatically provided pagination objects.showThe parameter is the key to controlling the number of pages displayed on the page, for example,show="5"It means displaying up to 5 numeric page link numbers before and after the current page number to maintain the simplicity of pagination navigation.

In addition to the basicshowOutside the parameters,paginationthe tag also provides aprefixParameter, this is usually a premium feature. It allows you to redefine the URL pattern of pagination links, for exampleprefix="?page={page}"In most standard application scenarios, AnQiCMS automatically handles the construction of URLs, thereforeprefixThe parameters usually do not need to be manually set.

paginationThe core fields provided by the tag

paginationThe tag encapsulates a comprehensive pagination data object, through these fields, we can accurately construct pagination navigation. These fields include:

  • TotalItemsThis indicates the total number of items in the document list, allowing users to understand the total amount of content.
  • TotalPagesThis shows the total number of pages in the document list, informing users how the content is distributed across multiple pages.
  • CurrentPage: Marks the current page being viewed by the user, which is crucial for the user to locate their own position.
  • FirstPage: An object containing a link to the first page and name, convenient for users to quickly return to the starting page.
  • LastPage: An object containing a link to the last page and a name, for easy user navigation to the end of the content.
  • PrevPage: An object containing a link to the previous page and its name, enabling sequential browsing.
  • NextPage: An object containing a link to the next page and its name, used to continue browsing the next page content.
  • Pages: This is an array object, containing the middle page number links, which is the core data for building the page number list.

Especially,PagesEach element in the array (which we callpageItem) also has its own fields, includingName(Page display name, such as "1", "2"),Link(The URL pointing to this page) as well asIsCurrent(A boolean value indicating whether the page number is the current active page).

How to build a flexible pagination style

BypaginationFields provided by the label, we can build highly customized pagination navigation. Below is a typical AnQiCMS pagination code example, showing how to combine these fields to implement a fully functional and style-controlled pagination:

First, make sure you have usedarchiveListtags totype="page"pattern to retrieve the document list data:

{# page 分页列表展示 #}
<div>
{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <div>{{item.Description}}</div>
            <div>
                <span>{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>{{item.Views}} 阅读</span>
            </div>
        </a>
        {% if item.Thumb %}
        <a href="{{item.Link}}">
            <img alt="{{item.Title}}" src="{{item.Thumb}}">
        </a>
        {% endif %}
    </li>
    {% empty %}
    <li>
        该列表没有任何内容
    </li>
    {% endfor %}
{% endarchiveList %}

    {# 分页代码 #}
    <div class="pagination-container">
        {% pagination pages with show="5" %}
        <ul class="pagination">
            {# 显示总数、总页码、当前页等信息 #}
            <li class="info">总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>

            {# 首页链接,根据IsCurrent状态添加active样式 #}
            <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 %}

            {# 中间数字页码列表,遍历Pages数组 #}
            {% 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 %}

            {# 末页链接,根据IsCurrent状态添加active样式 #}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
            </li>
        </ul>
        {% endpagination %}
    </div>
</div>

In this example, we firstdivandulTags provide structure to the pagination area, making it easy to style with CSS later. Each pagination link is wrapped inlitags and addedpage-itemclasses. We cleverly utilizeIsCurrentThe attribute dynamically added to the current page numberactiveclass, which allows us to highlight the current page through CSS rules (such as.pagination .active a { background-color: #007bff; color: white; }) to enhance visual feedback.

In addition, for the 'Previous page' and 'Next page' links, we use{% if pages.PrevPage %}and{% if pages.NextPage %}Perform conditional judgment to ensure that these navigation elements are only rendered when logically present, avoiding invalid links and further optimizing the user experience.This fine control allows you to freely adjust the layout, color, font, and all visual elements according to the design style of the website.

Conclusion

paginationTags serve as the core of AnQiCMS content list pagination, with a design philosophy that provides strong data support and high template rendering freedom.By flexibly using its parameters and built-in fields, and combining it with CSS for style control, you will be able to provide website visitors with an efficient and beautiful browsing experience, making the presentation of the content list even better.

Frequently Asked Questions

Q1: Why isn't pagination displaying on my page?A: First, please check yourarchiveListtags have been set.type="page"becausepaginationLabels are onlyarchiveListIt will work normally when fetching data in pagination mode. Secondly, make sure that your content list indeed contains more than one page of data. If there is not enough content to paginate, the pagination navigation will not be displayed naturally.Finally, please check the template inpaginationIs the syntax of the label correct, especially the variable namepageswhether it is witharchiveListThe variable of the returned pagination data is consistent

Q2: How to change the number of displayed page numbers in pagination?A: You can usepaginationlabel'sshowparameters to control the number of numeric page numbers displayed. For example,{% pagination pages with show="7" %}The links to more page numbers will be displayed before and after the current page number, with a total of up to 7 numeric page numbers.You can adjust this parameter based on the width of the page and design requirements to achieve **visual effects.

Q3: Can pagination be used in conjunction with search results or filtering conditions?A: Of course. AnQiCMS'paginationwith the tag andarchiveListand tightly integrated with tags,archiveListIt supports itselfq(Search keywords) and custom filtering parameters. This means that when a user is paging through search results pages or list pages with applied filtering conditions,paginationThe tag will automatically generate a new pagination link containing these search and filter conditions, ensuring that the search or filter criteria are retained when switching between page numbers, thus providing a seamless user experience.

Related articles

How to display all tags and document lists under tags in `tagList` and `tagDataList` tags?

As an experienced website operator who deeply understands the operation of Anqi CMS, I fully understand the core role of content organization and user experience in the success of a website.Tags are the important bridge connecting these two, they not only help us effectively classify and manage a vast amount of content, but also guide users to quickly find the information they are interested in.In Anqi CMS, the `tagList` and `tagDataList` template tags are the key tools to achieve this goal, allowing us to flexibly display tags and associated documents under the tags on the website front-end.###

2025-11-06

How to get the category list and detailed information of a single category with the `categoryList` and `categoryDetail` tags?

As a senior AnQi CMS website operation personnel, I know that the flexibility of content organization and presentation is crucial for attracting and retaining users.The site classification structure is not only the skeleton of content, but also an important path for users to explore and discover information.Today, let's delve deeply into the two core template tags in Anqi CMS, `categoryList` and `categoryDetail`, and how they help us efficiently obtain and display category lists and individual category details.## Flexible Construction of Category Navigation: `categoryList`

2025-11-06

How to get the detailed information of a specified document, including custom fields, using the `archiveDetail` tag?

In the daily operation of AnQi CMS, obtaining and displaying detailed information of website content is one of the core tasks.The `archiveDetail` tag is a powerful tool specifically designed for this purpose in the Anq CMS template system, allowing us to flexibly extract detailed data from any specified document, including standard document properties and user-defined field content.

2025-11-06

How to fetch the document list according to category ID, recommendation attributes, etc. for the `archiveList` tag?

As a senior security CMS website operator, I am well aware that the flexibility and powerful functions of the content management system tags are the key to efficient content operation.`archiveList` tag is the core tool used in AnQiCMS to retrieve document lists. The subtle use of its parameters can help us accurately present the desired content, whether it's building the recommended articles for the homepage, displaying specific documents on category pages, or providing related recommendations on detail pages, all of which rely on our proficiency with this tag.###

2025-11-06

How to format a timestamp to a specified datetime using the `stampToDate` filter in AnqiCMS template?

In the daily operation of AnQi CMS, the precise presentation of content is a key link to improve user experience and website professionalism.The formatting of dates and times is an indispensable part of it.As an experienced website operations manager, I am well aware of the readers' requirements for clear and consistent information.To help everyone better utilize the AnqiCMS template functions, this article will detail how the `stampToDate` filter formats timestamps into specified date and time in AnqiCMS templates.

2025-11-06

What are the core features and highlights of AnQiCMS?

As an experienced website operator, I have a deep understanding of the powerful functions of AnQiCMS and the actual value it brings to small and medium-sized enterprises, self-media operators, and multi-site managers.AnQiCMS is an enterprise-level content management system developed based on the Go language, and its design philosophy always revolves around providing an efficient, customizable, and easy-to-expand content management solution.It not only helps users simplify the content publishing process, but also helps websites stand out in the fierce market competition through a series of refined functions.

2025-11-06

How can AnQiCMS help small and medium-sized enterprises and content operation teams improve efficiency?

## AnQi CMS: A powerful tool to help small and medium-sized enterprises and content operation teams achieve efficient growth In today's digital wave, small and medium-sized enterprises and content operation teams are facing increasingly growing challenges in content management.From how to efficiently create, edit, and publish content, to how to improve the visibility of content in search engines, and how to effectively manage multi-site and multi-language content, every step tests the team's operational efficiency and market competitiveness.AnQiCMS (AnQiCMS) is an enterprise-level content management system designed to address these pain points, and it relies on its simple and efficient architecture and rich practical functions

2025-11-06

How to implement unified operations for the multi-site management function in AnQiCMS?

As a website operator who has been deeply involved with AnQiCMS for many years, I am well aware that in today's complex network environment, enterprises and content creators often need to manage multiple brand sites, sub-sites, or independent platforms established for different markets and user groups in different languages.The multi-site management function of AnQi CMS is specifically designed to meet such needs, it not only simplifies the cumbersome operational processes, but also provides strong support at the level of unified operations.### AnQiCMS

2025-11-06