How to implement pagination navigation display for content list in AnQi CMS?

Calendar 👁️ 57

When building a website using AnQiCMS, it is particularly important to have reasonable pagination navigation when you need to display a large amount of content, such as article lists, product lists, etc.It not only enhances user experience, making it easier for visitors to browse and find content, but also helps search engines better crawl the website.AnQi CMS provides a very intuitive and powerful pagination tag, making it easy to display the pagination of content lists.

Step 1: Prepare content list data

To implement pagination of the content list, first you need to usearchiveListThe tag is used to retrieve data. This tag is the core used to call various types of document lists in Anqí CMS.The key is that we need to clearly inform the system that this list needs to be paginated, rather than loaded all at once.

To this end, when usingarchiveListtags, you need totypethe parameter to"page". At the same time, throughlimitParameters to specify how many items to display per page. For example, if you want to display 10 articles per page under the current category, you can set it like this:

{% archiveList archives with type="page" limit="10" %}
    {# 循环显示文章内容 #}
    {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <p>{{item.Description}}</p>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            </a>
        </li>
    {% endfor %}
{% endarchiveList %}

Here, archivesIt is a custom variable name that contains all the article data on the current page. The followingforThe loop will iterate through these data, displaying the title, link, summary, and publish date of each article.

Step two: introduce pagination tags and build navigation.

InarchiveListThe tag retrieves and displays the content of the current page, and then it can introduce the Anqi CMS pagination tagpaginationIt generates the pagination navigation. This tag is usually placed inarchiveListclosing tag.

paginationA label needs a variable to store pagination information, usually we name itpages。“Furthermore,”showThe parameter is very practical, it determines how many page number buttons can be displayed at the same time in pagination navigation, for exampleshow="5"this means that up to 5 page number buttons are displayed.

The pagination tag provides a series of built-in objects and properties to help us build a complete navigation structure, including:

  • pages.TotalItemsTotal number of contents:
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: The current page number.
  • pages.FirstPage/pages.LastPageAn object pointing to the first and last pages.
  • pages.PrevPage/pages.NextPage: Points to the object of the previous and next pages.
  • pages.Pages: An array containing all the middle page number information, which can be accessed through.forLoop to traverse and display.

Each page number object (for example)pages.FirstPageorpages.Pagesofitem) all containName(Page display name),Link(Page link) andIsCurrent(Whether it is the current page, used for highlighting) and other properties.

Here is a general example of building a pagination navigation:

<div>
    {% 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 %}

            {# 中间页码循环 #}
            {% 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, you will get a fully functional pagination navigation that includes the first page, previous page, next page, last page, as well as the page number links in the middle, and the current page will haveactiveStyle class for highlighting.

Complete example: article list and pagination navigation

Combine these two steps and you can easily implement pagination navigation display of content lists in Anqi CMS.

<div class="article-list-container">
    {# 第一步:获取需要分页的文章列表数据 #}
    {% archiveList archives with type="page" limit="10" %}
        {# 循环显示文章内容 #}
        {% for item in archives %}
            <div class="article-item">
                <a href="{{item.Link}}">
                    <h3>{{item.Title}}</h3>
                    <p>{{item.Description}}</p>
                    <small>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</small>
                </a>
            </div>
        {% empty %}
            <p>该分类下暂时没有文章。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 第二步:生成分页导航 #}
    <div class="pagination-container">
        {% pagination pages with show="5" %}
            <ul class="pagination-nav">
                <li class="pagination-info">总计:{{pages.TotalItems}}条,共{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>

                <li class="page-link-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                    <a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
                </li>

                {% if pages.PrevPage %}
                    <li class="page-link-item"><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
                {% endif %}

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

                {% if pages.NextPage %}
                    <li class="page-link-item"><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
                {% endif %}

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

By using these simple tag combinations, Anqi CMS can help you quickly add pagination features to website content, whether it's articles, products, or other custom content models, which can be easily realized, greatly enhancing the practicality and user experience of the website.

Frequently Asked Questions (FAQ)

1. Why is the pagination navigation not displayed on my content list page?

Generally speaking, this may be because when usingarchiveListortagDataListthe content list tags, you have not settypethe parameter to"page". Only whentype="page"When, Anqi CMS will calculate the pagination information and provide it topaginationUse the tag. Also, checklimitWhether the parameters are set properly, if the total number of contents is not enough for a page (i.e., less than or equal tolimitValue), the system will not display pagination navigation.

2. How to adjust the number of items displayed per page?

To adjust the number of items displayed per page, simply modifyarchiveListin the labellimitthe parameter value. For example, tolimit="10"changed tolimit="20"This parameter directly determines the number of items displayed per page and the density of content per page.

3. How is the pagination link URL generated? Can I customize it?

The pagination link URL format of AnQi CMS is automatically generated based on the static rules you configure in the background. For example, if you choose the numeric mode, the link may look like/archive/page-2.htmlThis; if it is a model naming pattern, it may contain the model name. Usually, the default pseudo-static rules can meet most needs. If you need highly customized, you canpaginationUsed in tagsprefixParameters to redefine the URL pattern, but this feature is quite advanced and needs to include{page}Placeholders to indicate the page number location, and make sure it matches the routing rules of your website.

Related articles

How to call and display the friendship link set in the background on the front end?

AnQiCMS (AnQiCMS) provides a set of intuitive and powerful content management features, among which the management of 'friend links' is an indispensable part of website operation. It not only promotes the SEO performance of the website but also provides users with convenient navigation.This article will give a detailed introduction on how to call and elegantly display the friendship links you set in the background. ### Friend link backend configuration Managing friend links in Anqi CMS is very simple.You just need to log in to the back-end, find the "Function Management" module in the left menu bar, click to enter "Friend Links". Here

2025-11-08

How to display the message form submitted by users on the website?

A highly efficient and flexible mechanism is provided by Anqi CMS to easily display and manage user message forms on your website.Whether it is to collect user feedback, consultation, or simple interactive messages, Anqi CMS can help you quickly implement this function and customize it according to your business needs. ### Learn about the Anqi CMS message function In the Anqi CMS backend management interface, you can find the "Website Message" option under the "Function Management" menu.This is the core area where you manage all comment-related settings, including viewing submitted comments and customizing form fields

2025-11-08

How to implement the pagination display function of the article comment list?

In website operation, effectively managing and displaying user comments is crucial for enhancing user interaction and content vitality.AnQiCMS (AnQiCMS) is a powerful content management system that provides flexible template tags, allowing us to easily implement pagination display of article comment lists.This article will introduce in detail how to implement this feature through template tags in Anqi CMS, thus providing users with a better browsing experience.Understanding the core of comments and pagination In the Anqi CMS template system, implementing pagination display of article comment lists

2025-11-08

How to use Tag tags to associate and display related content on the front end?

In Anqi CMS, content organization and association is the key to enhancing website value, optimizing user experience, and improving search engine performance.In addition to the traditional classification structure, we also have a very powerful and flexible tool - Tag tag.It is like a 'living index' of content, which helps us to connect scattered content in multiple dimensions, making it easier for users to find the information they are interested in.Today, let's talk about how to make full use of Tag tags on the front end to associate and display our wonderful content.### Tag label: Flexible content association bridge Different from a strict classification system

2025-11-08

How to embed mathematical formulas and flowcharts in a page and ensure correct rendering display?

In website operation, we often need to display some professional content, such as mathematical formulas involving scientific calculations, or complex flowcharts for business process descriptions.The traditional way of displaying this content is often inefficient, difficult to maintain, and also does not provide a good reading experience.AnQiCMS combines its powerful content management capabilities and support for Markdown to provide us with an elegant solution.By simply introducing some external libraries and enabling the Markdown editor, we can display the professional content correctly on the website page

2025-11-08

How to safely output HTML tags in website content to avoid escaping?

In website content management, especially when content includes rich formats or user input, how to safely output HTML tags is a crucial issue.AnQiCMS (AnQiCMS) fully considered this from the beginning, its template engine defaults to escaping output variables to effectively prevent cross-site scripting attacks (XSS) and other security risks.### Understanding the Default Behavior of Template Engines The Anqi CMS template engine follows the syntax of mainstream frameworks like Django, one of its core concepts being 'Security First'

2025-11-08

How to truncate long text content and add an ellipsis at the end to optimize list display?

In website operation, especially managing a content-rich platform, the display effect of the list page is crucial for user experience.Whether it is an article list, product overview, or news update, we hope the page is tidy and the information is clear at a glance.However, when the document content or description is too long, directly displaying it in the list often leads to layout confusion, affecting the overall aesthetics and information acquisition efficiency.At this moment, effectively truncating text and adding an ellipsis is particularly important.AnQiCMS (AnQiCMS) provides a powerful and flexible template system, in which built-in text filters can help us easily solve this problem

2025-11-08

How to convert image addresses to thumbnail format for display?

In website operation, images play a crucial role.They can not only attract users' attention but also effectively convey information.However, very large images can severely affect website loading speed, thereby damaging user experience and search engine rankings.Therefore, converting the image address to a thumbnail format for display has become an indispensable part of optimizing website performance.AnQiCMS provides very convenient features in this aspect, it can automatically generate and manage thumbnail images for your website, and also provides flexible calling methods to help you easily meet the challenges of image optimization.### AnQiCMS

2025-11-08