How to display pagination links in AnQiCMS and control the number of page numbers displayed?

Calendar 👁️ 65

In website operation, efficiently managing and displaying a large amount of content is the key to improving user experience.When the content list is too long, a reasonable pagination mechanism not only makes it easier for users to browse but also optimizes the page loading speed, indirectly improving the search engine friendliness.In AnQiCMS, implementing pagination functionality and flexibly controlling the display quantity of page numbers is a relatively direct and powerful process.


Elegantly display pagination links and flexibly control the number of page numbers in AnQiCMS

On your AnQiCMS website, when the number of articles, products, or other list items increases, you will find that stacking all the content on a single page is not conducive to user browsing and may also affect the page loading speed.At this time, the pagination feature is particularly important. AnQiCMS provides intuitive template tags to help you easily implement the pagination display of content, and can flexibly adjust the display style of page numbers according to your needs.

Prepare pagination data: Enable pagination mode for the list

To use the pagination feature of AnQiCMS, first make sure that your data list tags (such asarchiveListused for article/product lists,commentListused for comment lists,tagDataListThis is used to configure pagination for the list of articles associated with tags. This is done by adding in the tagtype="page"Parameter to achieve.

For example, if you want to display a list of articles on a page and want it to support pagination, you can write it like thisarchiveListTags:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <p>{{item.Description}}</p>
            </a>
        </li>
    {% empty %}
        <li>当前列表没有任何内容。</li>
    {% endfor %}
{% endarchiveList %}

Here, type="page"Tell the system that this list needs pagination processing, andlimit="10"It specified that 10 items are displayed per page. The system will store the query results inarchivesthe variable for you to loop through.

To display pagination links: usepaginationTag

Once the data list is ready, the next step is to use the AnQiCMS providedpaginationThe tag generates and displays pagination navigation. This tag is very intelligent, as it automatically generates a complete page number navigation structure based on the context of the current page (such as the total number of items, the current page number, etc.)

paginationThe basic usage of the tag is as follows:

{% pagination pages with show="5" %}
    {# 在这里放置您的分页链接HTML结构 #}
{% endpagination %}

In{% pagination %}tags, we define a variable namedpagesto receive all pagination information. ThispagesAn object contains all the data needed to build pagination navigation, such as:

  • TotalItems: Total number of content items.
  • TotalPages: Total number of pages.
  • CurrentPage: The current page number.
  • FirstPage: Home object, including links (Link) and names (Name), and whether it is the current page (IsCurrent)
  • LastPage: End page object, structure andFirstPageSimilar.
  • PrevPageThe previous page object exists only when it is not the first page.
  • NextPageThe next page object exists only when it is not the last page.
  • PagesAn array containing all the middle page number objects, each object also hasLink/NameandIsCurrentProperty.

CombinearchiveListTag, here is a complete pagination navigation code example:

{# 假设这里是您的内容列表(与上文 archiveList 示例代码相同) #}
{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <p>{{item.Description}}</p>
            </a>
        </li>
    {% empty %}
        <li>当前列表没有任何内容。</li>
    {% endfor %}
{% endarchiveList %}

{# 分页导航区域 #}
<div class="pagination">
    {% pagination pages with show="5" %}
    <ul>
        {# 显示总页数和当前页信息 #}
        <li>总计 {{pages.TotalItems}} 条,共 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页</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 %}

        {# 中间页码链接,循环 pages.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 %}

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

In this example, we usepagesAn object's various properties build a complete pagination navigation that includes home page, previous page, middle page numbers, next page, and last page. Byitem.IsCurrentproperties, you can easily add the current page number toactiveMake the class highlight visually to enhance user experience.

Control the number of pages displayed:showThe magic of parameters

Flexibly control the number of page numbers displayed in pagination navigation, which is the key to improving user experience and page simplicity. AnQiCMSpaginationTag throughshowparameters, allowing you to easily achieve this.

showThe value is an integer that specifies how many page numbers to display before and after the current page. For example:

  • show="3": If the current page is the 5th page, it will display, in addition to the current page... 2 3 4 [5] 6 7 8 ...Such page number structure, a total of displaying 3 page numbers before and after the current page.
  • show="5": Displaying 5 page numbers before and after the current page.
  • show="0"If you only want to display navigation such as 'Previous page', 'Next page', 'Home', 'End page', etc., and do not need to display specific page numbers, you canshowis set to0.

You can adjust according to the design style of the website and the user's habitsshowThe value. For example, websites with a large amount of content and the need for quick navigation can be appropriately increasedshowThe value, while a website with a flat content structure can maintain a smallershowvalue to keep the page tidy.

Just modifypaginationin the labelshowJust set the parameters:

{# 显示当前页码前后各2个页码 #}
{% pagination pages with show="2" %}
    {# ... 您的分页链接HTML结构 ... #}
{% endpagination %}

Practical application and precautions

  • Ensure that the data list enables pagination:Again emphasize, only when your data list tag (such asarchiveList) is settype="page",paginationthe tag can be normal

Related articles

How to retrieve and display custom form fields in AnQiCMS comment form?

When using AnQiCMS to manage website content, the online message function is undoubtedly an important means of interacting with visitors, collecting feedback, or gathering potential customer information.In addition to the basic name, contact information, and message content, we often need to collect more specific and personalized information, such as 'Your project budget', 'The type of service you are interested in', or 'The expected contact time'.AnQi CMS provides a flexible custom message field function, allowing us to easily meet these needs.How can I retrieve and elegantly display these custom form fields on the website front page?

2025-11-08

How to display user comment lists and implement pagination in AnQiCMS?

In website content operation, user comments are an important part of enhancing interactivity and activity, and reasonable pagination can ensure that the comment list is both complete and loads smoothly.AnQiCMS (AnQiCMS) provides powerful and flexible template tags, allowing you to easily display and manage user comments on the front-end page, and implement pagination functionality for the comment list.

2025-11-08

How to use AnQiCMS tags to display the document list under a specific Tag?

In AnQiCMS, tags are a powerful content organization method that helps us associate content with different categories and models more flexibly.Using labels appropriately can not only optimize the SEO performance of a website, but also significantly improve the user's experience in discovering content on the website.When we want to focus on displaying all relevant documents under a specific tag, AnQiCMS provides a set of intuitive and efficient template tags to meet this need.This article will introduce in detail how to use the built-in template tags of AnQiCMS

2025-11-08

How to display the list of related documents in AnQiCMS, what is the logic?

How to effectively guide users to discover more interesting content in a content management system is the key to improving user experience and website depth.AnQiCMS handles the 'related document list' feature by providing a flexible and intelligent mechanism that allows us to easily display other articles or products closely related to the current content on the website. This not only helps to extend the user's stay on the website but also optimizes the search engine crawling efficiency through internal links.### AnQiCMS

2025-11-08

How to set and display the global information of AnQiCMS, such as Logo, filing number, and copyright?

AnQiCMS provides an intuitive and powerful way to manage and display the global information of the website, such as the website logo, filing number, and copyright statement.This information is not only an important part of the website's brand image, but also concerns the legal and compliant operation of the website.The detailed introduction on how to set and utilize these global information will follow. ### Set global information in the background All the global information of the website is concentrated in the "Global Function Settings" of AnQiCMS backend.

2025-11-08

How to implement conditional logic in AnQiCMS to control the display of content?

In website operation, displaying different content based on different conditions is the key to improving user experience and achieving refined operation.AnQiCMS provides powerful and flexible template tags and logical judgment functions, allowing us to easily implement conditional display of content, thereby meeting various business needs.This article will delve into how to make use of the template engine features in AnQiCMS, controlling the display of website content precisely through conditional logic judgments.

2025-11-08

How does the AnQiCMS template loop through arrays or objects to display list data?

In the Anqi CMS template system, the core of looping through arrays or objects and displaying list data lies in understanding its Django-like template syntax, especially the use of the `for` loop tag.This mechanism makes the presentation of dynamic content intuitive and efficient, whether it is for article lists, category navigation, or product displays, it can adapt flexibly. ### Core Mechanism: The Use of `for` Loops Data traversal in Anqi CMS templates mainly relies on `{% for ...in ...

2025-11-08

How to format a timestamp in AnQiCMS template and display it in a specified date format?

In AnQiCMS template, processing timestamps and displaying them in a specific date format is a common requirement in content operation.No matter whether you need to display the publication time of the article or the update date of the product, understanding how to flexibly format time will greatly enhance the expressiveness of the website content.AnQiCMS provides simple and powerful template tags, making this process easy and convenient.

2025-11-08