How to correctly configure the `pagination` tag to generate a functional pagination navigation on the list page?

Calendar 👁️ 61

In website content management, configuring a feature-rich pagination navigation for the list page is a key factor in improving user experience and optimizing website structure. AnqiCMS (AnqiCMS) provides a simple yet powerfulpaginationLabels, allowing developers to easily implement this requirement.

To makepaginationLabels correctly generate pagination navigation on the list page, first you need to understand its working mechanism as well as with content list labels (such asarchiveListCollaboration between them.paginationThe tag does not exist independently; it needs to obtain pagination data from the content list tag. This means that in your template file, you must use it first.archiveListSuch content list tags to query data, and specify the type as pagination mode, thenpaginationTags can be based on this data to build pagination navigation.

Configure the content list label to support pagination

You need to use pagination navigation on any list page that requires it, such as article list pages, product list pages, or category list pages,archiveListLabel to retrieve article or product data. The key is that you need totypethe parameter to"page"and throughlimitParameters define the number of items displayed per page.

For example, if you want to display 10 articles per page on a page, you can configure it like thisarchiveListTags:

{% archiveList archives with type="page" limit="10" %}
    {# 循环输出每篇文章的简要信息 #}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <div>{{item.Description}}</div>
        </a>
    </li>
    {% endfor %}
{% endarchiveList %}

Here, archivesIs a variable name that will contain the article data for the current page.type="page"Tell AnQi CMS that this is a paginated list, andlimit="10"then set the number of items per page.

Deep understandingpaginationLabel configuration

InarchiveListAfter the label, you can introducepaginationuse,a,tag,to,create,pagination,navigationpaginationThe usage method of the label is as follows:

{% pagination pages with show="5" %}
    {# 在这里构建您的分页导航 HTML 结构 #}
{% endpagination %}

here,pagesis a variable that contains all the pagination information, it is generated byarchiveList type="page"automatically.show="5"The parameter specifies the maximum number of page buttons to display in the pagination navigation. For example, if there are a total of 10 pages,show="5"It may display the current page number and 5 pages before and after it, instead of all 10 pages.

pagesThe variable contains rich pagination status and link information, you can use it to build a complete pagination navigation:

  • pages.TotalItems: Total number of items.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: Current page number.
  • pages.FirstPage: Home object, includingName(such as 'Home') andLink.
  • pages.LastPage: The end page object includesName(For example, 'end page') andLink.
  • pages.PrevPage: The previous page object includesName(For example, 'previous page') andLink. If it is the first page, this object is empty.
  • pages.NextPage: The next page object includesName(For example, "next page") andLink. If it is the last page, this object is empty.
  • pages.Pages: An array that includes detailed information of middle page numbers, each element containsName(page number),LinkandIsCurrent(Is this the current page?).

Use this information to design a flexible pagination navigation layout.A common feature-rich pagination navigation will include elements such as 'Home', 'Previous page', 'Middle page numbers', 'Next page', and 'End page'.

Here is a recommended, complete and easy-to-understand pagination navigation implementation example:

<div class="pagination-nav">
    {% pagination pages with show="5" %}
    <ul>
        {# 显示总数信息,方便用户了解列表规模 #}
        <li>共 <b>{{pages.TotalItems}}</b> 条记录,<b>{{pages.TotalPages}}</b> 页,当前第 <b>{{pages.CurrentPage}}</b> 页</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>

By this structure, you can easily add styles to pagination navigation using CSS, such as highlighting the current page number or hiding non-clickable 'Previous'/'Next' buttons.

Combine search and filter functions

It is worth mentioning that the Anqi CMSpaginationTags can also be seamlessly integrated with search and filter functions. When yourarchiveListThe page containing your tags includesqParameters (search keywords) or custom filter parameters when,paginationThe tag-generated link will automatically include these parameters to ensure that the search and filtering conditions are still valid when the user navigates to the next page.This greatly simplifies the work of developing complex list pages, no need to manually handle URL parameters.

In short, proper configurationpaginationTags are the foundation for building efficient, user-friendly CMS website list pages. By understandingarchiveListwithpaginationthe relationships and utilizingpagesInformation provided by the variable is rich, you can easily implement powerful pagination navigation.


Frequently Asked Questions (FAQ)

1. Why did I configurepaginationBut there is no pagination navigation displayed on the page?

The most common reason is that the tag (such asarchiveListortagDataList) is not set correctlytype="page"parameter is not set or not configuredlimitParameter.paginationThe label needs this information to know how to paginate and how many items to display per page. Please ensure that your content list label is similar to{% archiveList archives with type="page" limit="10" %}.

How to customize the style and layout of pagination navigation?

paginationTags provide the dynamic data and links needed for pagination, and the specific HTML structure and CSS style are completely under your control. You can{% pagination pages with show="5" %}...{% endpagination %}Between the code blocks, use HTML tags (such asul,li,a) combined with CSS class names to design the appearance you want. For example, you can useclass="active"Mark the current page number and then highlight it through CSS rules.

3. Does the search and filter function on my list page lose these conditions when paginating?

I won't. Anqi CMSpaginationThe tag is designed very intelligently, it will automatically inherit the search keywords from the current page URL (qParameters and any custom filter parameters. This means that when users navigate through pages on search or filter result pages, the generated pagination links will automatically retain these query parameters, ensuring a consistent user experience.You do not need to make any additional configuration to handle this situation.

Related articles

How to get and paginate the display of all relevant documents under a specific `tagDataList` tag?

When managing content in Anqi CMS, tags (Tag) are an important tool for organizing and categorizing information.It can not only help users quickly find relevant content, but also significantly improve the internal link structure and SEO performance of the website.When it is necessary to display all relevant documents under a specific tag and to manage pagination, the `tagDataList` tag becomes an indispensable core function.

2025-11-07

How to use the `prevArchive` and `nextArchive` tags to navigate to adjacent documents in the article detail page?

In today's content-driven world, the user experience of the website article detail page is particularly important.When a reader is immersed in an excellent content, if they can navigate smoothly to related or adjacent articles, not only can it extend their stay on the website and increase the page views, but it can also indirectly optimize the search engine crawling and ranking through the internal link structure.AnQi CMS is an efficient and SEO-friendly content management system that fully considers these details and provides simple and intuitive template tags to help us easily achieve this function. Today

2025-11-07

How to implement hierarchical display and nested calling of the `categoryList` tag?

Building a clear and organized website navigation in AnQiCMS is crucial for improving user experience and website accessibility, especially when dealing with multi-level categories.The `categoryList` tag was created for this purpose, providing powerful features to help us flexibly display the hierarchical structure of categories and make fine-grained nested calls.

2025-11-07

How to retrieve the title, content, image, and custom fields of a specific document using the `archiveDetail` tag?

How to use the `archiveDetail` tag in AnQiCMS to finely control the display of document content?AnQiCMS as an efficient and flexible content management system, one of its core advantages lies in its powerful content display capabilities.For each independent article, product detail, or any other 'document' type of content on the website, we hope to fine-tune their display methods on the front page.This is the place where the `archiveDetail` tag really shines.

2025-11-07

How to use the `stampToDate` tag to format a timestamp into a custom date and time format?

Good, I'm glad to deeply interpret the `stampToDate` tag of AnQiCMS, helping you easily control the time display on the website. --- ## Flexible Time Mastery: Customize Date and Time Format with AnQiCMS `stampToDate` Tag The way dates and times are displayed on a website often directly affects user experience and the clarity of information communication in content management.A concise and readable date format allows visitors to quickly understand the timeliness of the content. AnQiCMS

2025-11-07

How to dynamically generate page title, keywords, and description with the `tdk` tag and flexibly control whether to include the website name?

In website operation, the page title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, are the foundation of search engine optimization.They can not only help search engines understand the page content, but are also key factors to attract users to click.AnQiCMS (AnQiCMS) fully understands the importance of TDK, and through its powerful template tag system, especially the versatile `tdk` tag, makes dynamic generation and flexible control of page TDK easy and efficient.

2025-11-07

How to construct a website navigation with multi-level submenus and associated content using the `navList` tag?

When building a website, a clear and easy-to-use navigation system is crucial, as it directly affects whether users can quickly find the information they need and also influences how search engines understand the structure of the website.AnQiCMS provides a powerful `navList` tag, allowing us to flexibly build a navigation system with multi-level submenus and closely associate navigation items with website content.Next, we will delve into how to use the `navList` tag to create a set of multi-level navigation that is both beautiful and practical for your website.### Website Navigation Basics

2025-11-07

How to create a dynamic breadcrumb navigation using the `breadcrumb` tag and customize the home page name and title display?

In website operation, a clear navigation path is crucial for user experience and search engine optimization (SEO).Breadcrumb Navigation is like a small map of a website, allowing visitors to always know their location and easily return to the previous page.Today, let's delve deeper into how to use the powerful `breadcrumb` tag in Anqi CMS to create dynamic breadcrumb navigation and customize the home page name and title display according to our needs.

2025-11-07