How to use the pagination tags of AnQiCMS to control the display of list content?

Calendar 👁️ 66

In a content management system, how to effectively display a large amount of information without sacrificing user experience is always a thought-provoking question.AnQiCMS provides a powerful and flexible pagination feature, allowing website administrators to finely control the display of list content, ensuring that the website is both beautiful and efficient.

To implement pagination control of list content, we need to understand the collaborative role of two core template tags in AnQiCMS: the first is responsible for obtaining and preparing list data, such asarchiveList(Document list),tagDataList(Tag document list) orcommentList(Comment list); next, it is specifically used for generating pagination navigationpaginationTags. When used together, they can build dynamic, user-friendly content lists.

Prepare content lists:archiveListWith pagination mode

In AnQiCMS, when we want to display a series of documents, products, or other content,archiveListIt is the most commonly used tag.Its main responsibility is to retrieve content from the database and filter and sort it according to our needs.archiveListSet a specific parameter for the tag:type="page".

Whentypethe parameter is set topagethen,archiveListIt is no longer just a simple list of all content that meets the conditions, but intelligently retrieves data based on the current page number and the number of items displayed per page. At the same time, we also need to go throughlimitParameters to specify the number of items to display per page. For example,{% archiveList archives with type="page" limit="10" %}This code tells the system to retrieve the content list for pagination display and show 10 items per page.

archiveListTags can be filtered by various conditions, such as throughcategoryId(Category ID) to get content under a specific category, throughorder(Sorting method) sorted by publish time or view count, even throughqSearch keyword to display the pagination of search results. These flexible parameters enablearchiveListto become the cornerstone of building a diverse content list.

Building pagination navigation:paginationThe art of tags

OncearchiveList(or other list tags) withtype="page"pattern retrieved pagination content, next is to display pagination navigation. At this time,paginationtag comes into play. This tag is usually followed by the content list'sforAfter the loop, it will generate "Previous page

paginationThe most commonly used parameter of the tag isshowIt determines how many page number links are displayed at the same time in the page navigation. For example,show="5"It will make the pagination navigation only display 5 page number links around the current page, which is very helpful for keeping the page neat and avoiding a long page number bar.

paginationThe tag will return a namedpagesThe object (if you specify another variable name in the label, then use the one you specify). ThispagesThe object includes all the details about the pagination status, which is crucial for us to build custom pagination styles. The fields we can access include:

  • pages.TotalItems: Total number of contents.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: The current page number.
  • pages.FirstPage: Home link information (including)Name/Link/IsCurrent)
  • pages.LastPage: End page link information.
  • pages.PrevPage: Previous page link information.
  • pages.NextPage: Next page link information.
  • pages.PagesAn array, containing the page link information of the middle part, we can iterate over it to generate page numbers such as 1, 2, 3... Each array element also containsName/LinkandIsCurrentProperty.

Utilizing these rich fields, we can control the display logic and style of pagination navigation through conditional judgment ({% if %}) and loop ({% for %}) to fine-tune the display logic and style of pagination navigation. For example, by checkingIsCurrentAttribute, we can add a page number to the current oneactiveClass, to highlight.

Comprehensive Application Example

Let's look at how these two tags work together with a simple example:

{# 1. 使用 archiveList 获取分页内容,每页显示10条 #}
{% archiveList archives with type="page" limit="10" %}
    {# 遍历并显示内容列表 #}
    {% for item in archives %}
    <div class="content-item">
        <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
        <p>{{ item.Description }}</p>
        <span class="meta">{{ stampToDate(item.CreatedTime, "2006-01-02") }} | {{ item.Views }} 次浏览</span>
    </div>
    {% empty %}
    <p>抱歉,当前分类或搜索条件下没有找到任何内容。</p>
    {% endfor %}
{% endarchiveList %}

{# 2. 使用 pagination 标签生成分页导航,并控制显示逻辑 #}
<div class="pagination-nav">
    {% pagination pages with show="5" %}
    <ul>
        {# 显示总数信息 #}
        <li class="page-info">共 {{ pages.TotalItems }} 条记录,当前第 {{ pages.CurrentPage }}/{{ pages.TotalPages }} 页</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 the above code, AnQiCMS can intelligently determine the page number parameter in the current URL (usuallypage=N), automatically handles content retrieval and pagination link generation.This divide-and-conquer template design concept makes the pagination control of the content list intuitive and powerful.Whether it is to build a blog article list, a product display page, or a search results page, it can easily achieve efficient and user-friendly pagination experience.


Frequently Asked Questions (FAQ)

1. Why did I write the example code, but the page still only shows the first page content without pagination navigation?

This is usually because you arearchiveListIn the (or similar list label) forget to settype="page"Parameter.paginationThe label needs to work in pagination mode to get the total number of pages, current page, and other information to generate navigation. Please check yourarchiveListDoes the label containtype="page"For example{% archiveList archives with type="page" limit="10" %}.

2. How to change the number of items displayed per page, for example, from 10 to 20?

The number of items displayed per page is determined byarchiveListlabel'slimitParameter control. Just modify the value of this parameter, for example,limit="10"changed tolimit="20"The system will adjust the number of items displayed per page and the total number of pages accordingly.

3. How to customize pagination navigation styles, for example, making the current page number display in red?

The style of pagination navigation is completely controlled by CSS.paginationTag generation:pagesEach page in the object

Related articles

How to get and display the previous and next article links of AnQiCMS articles?

In website content operation, guiding users to smoothly browse related content is a key link to improving user experience and website depth.After a user finishes reading an article, if they can immediately see links to related or sequential previous and next articles, it will undoubtedly encourage them to continue exploring. This not only helps to reduce the bounce rate but also effectively improves the website's PV (page views) and SEO performance.AnQiCMS (AnQiCMS) is an efficient content management system that provides a very convenient way to implement this function.In AnQi CMS

2025-11-07

How to implement Markdown format content rendering and display on the AnQiCMS web page correctly?

In the digital age, the efficiency of content creation and publishing is the key to the success of the website.Markdown as a lightweight markup language, with its concise and efficient features, is increasingly favored by content creators.AnQiCMS knows this need, providing excellent Markdown support to users, making content creation more convenient, while ensuring that the web page presents a beautiful and clear structure.

2025-11-07

How to ensure that the encoding of AnQiCMS template files is correct to avoid page garbled characters?

When using AnQiCMS to build a website, we may encounter abnormal display of pages, with garbled characters.This is usually due to incorrect encoding settings in the template file.Ensure that the template file uses the correct encoding is a key step to avoid such problems, ensure the normal operation of the website, and provide a good user experience.AnQiCMS as a modern content management system, its internal processing and recommendation standards tend to use UTF-8 encoding.UTF-8 is an international character encoding that can be compatible with the characters of most languages in the world, including Chinese

2025-11-07

How to flexibly display custom content model fields on the front page of AnQiCMS?

In the world of content management, flexibility is the key to website success.Most of the time, we find that the standard "article" or "product" content model cannot fully meet our unique business needs, such as the need to add unique attributes such as "material", "size", etc. for a specific type of product, or to add information such as "registration deadline", "event location", etc. to the activity detail page.At this moment, the powerful custom content model function of AnQiCMS can fully show its strength.

2025-11-07

How to display custom Banner images on AnQiCMS pages?

In website operation, skillfully using Banner images can not only beautify the page but also effectively convey information and guide user behavior.AnQiCMS as a flexible content management system, provides various ways to display customized Banner images, allowing you to configure them individually according to different pages and needs. ### Flexible Upload and Management of Banner Images Firstly, all images that are going to be used as banners need to be uploaded to the AnQiCMS media library.This is very simple, you can go to the 'Page Resources' menu in the backend

2025-11-07

How to display AnQiCMS single-page content and related images?

In website operation, we often need to create some independent pages, such as "About UsThese pages contain relatively fixed content, do not belong to the conventional article or product list, AnQiCMS (AnQiCMS) classifies them as "single page" and provides a very convenient management and display method.Through this system, you can easily publish and update this content, while flexibly controlling their display styles and image presentation.

2025-11-07

How to display category introduction, Banner image and thumbnail on AnQiCMS category page?

In website operations, the category page is not only an aggregation of content, but also an important entry for users to understand the website structure and explore specific topics in depth.A well-designed, informative category page that can significantly improve user experience and search engine optimization (SEO) effectiveness.AnQiCMS provides flexible features, allowing us to easily display category descriptions, banner images, and thumbnails on the category page, giving your website's category page a fresh look.Understanding AnQiCMS's category page and template structure In AnQiCMS

2025-11-07

How to filter and display AnQiCMS document list according to category ID and recommendation attributes?

Manage website content in AnQiCMS, often need to display document lists according to different conditions.Whether you want to display the latest articles of a specific category on the homepage or highlight some recommended content in the sidebar, the system provides flexible tools to help us achieve this.Today, let's talk about how to cleverly use category ID and recommendation attributes to accurately filter and display the document list you want.

2025-11-07