How to use the `pagination` tag to build standard pagination navigation in the template?

Calendar 81

When the content of a website becomes rich, a clear and efficient pagination navigation system is crucial for improving user experience. AnQiCMS (AnQiCMS) template system provides powerfulpaginationTags, let us easily build standardized, beautiful pagination navigation. Next, we will delve deeper into how to use this tag in templates.

UnderstandingpaginationThe role of the tag

paginationThe tag is a component designed specifically for pagination functions in the Anqi CMS template system.Its main task is to generate a series of pagination links based on the data of the content list, making it convenient for users to navigate between multiple pages.This tag usually needs to be used with content list tags that support pagination functionality, such asarchiveList/tagDataListUse it together. When your content list tag is set to pagination mode (i.e.type="page"),paginationtag can get the corresponding pagination data and render it into navigation links.

paginationThe tag provides two main parameters to flexibly control the display of pagination navigation:

  • showThis parameter is used to control the number of page numbers visible in the pagination navigation. For example, setshow="5"This means that up to 5 page number links will be displayed before and after the current page number. When the total number of page numbers is large, the excess part will be omitted to keep the pagination navigation bar concise and avoid being too long.
  • prefixThis is a more advanced parameter, used to redefine the URL pattern of pagination links.In most cases, Anqi CMS will automatically handle the generation of URLs, and you usually do not need to set it manually.If your website has special requirements, such as adding custom parameters to the page number links, you can use it.However, please note,prefixmust contain{page}placeholder, for exampleprefix="?page={page}".

paginationlabel returns the data structure

paginationThe tag returns an object containing rich pagination information. In the template, we usually assign a variable name to this object (such aspages), then access its properties through this variable. ThispagesThe object will contain the following key information:

  • TotalItems: indicates the total number of content records.
  • TotalPages: indicates how many pages the content is divided into.
  • CurrentPage: Indicates the page number the user is currently browsing.
  • FirstPage: An object containing the name of the home page (Name, usually "home" or "1") and the link (Link)). It also has anotherIsCurrentProperty used to determine if it is the current page.
  • LastPage: An object containing the name of the last page (Name) and the links(Link) which also hasIsCurrentProperty.
  • PrevPageA object containing the name and link of the previous page. This object may not exist if the current page is the first page.
  • NextPageA object that contains the name and link of the next page. This object may not exist if the current page is the last page.
  • PagesThis is an array that contains detailed information about the middle page number, which needs to be processed throughforLoop to traverse and display.
    • PagesEach element in the array (for example, it can be named in a loop) contains the following fields:itemThe following fields are included:
      • Name: The display name of the page number (usually just the page number).
      • Link: The URL link corresponding to the page number.
      • IsCurrentA boolean value indicating whether the current page number being cycled through is the page the user is currently visiting. This is very useful for adding special styles (such as highlighting) to the current page.

Actual operation: Build standard pagination navigation

Now, let's build a standard pagination navigation through a practical example. Suppose we are adding pagination functionality to an article list page.

First, make sure your content list tag (here usingarchiveListas an example) is set to pagination mode and specify the number of items per page.

`twig

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <!-- 这里是每篇文章的显示内容,例如标题、简介等 -->
    <article class="article-item">
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description }}</p>
        <div class="article-meta">
            <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            <span>阅读量:{{ item.Views }}</span>
        </div>
    </article>
    {% empty %}
    <p class="no-content">暂无文章可显示。</p>
    {% endfor %}
{% endarchiveList %}

{# 分页导航区域开始

Related articles

How to display the number of comments for each article on the article list page?

In website operation, the article list page is not only the entrance of content, but also a window for users to understand the activity level of the website.When users see that every article is accompanied by a comment count, this not only effectively enhances the interactivity and attractiveness of the article, but also brings positive social proof to the website, encouraging more readers to participate in discussions.For users who use AnQiCMS, displaying the number of comments for each article on the article list page is a very direct and practical feature.

2025-11-07

How to ensure that the website displays a custom prompt to users when it is in "shutdown" status?

In website operation, we sometimes encounter situations where we need to temporarily close the website, such as for system maintenance, major upgrades, data migration, or dealing with unexpected security events.For any reason, directly allowing users to access a blank page or an error page will severely affect user experience and even damage the brand image.At this time, it is particularly important to clearly display a friendly prompt message to visitors.

2025-11-07

How to call and display the independent domain of the website backend configured in the template?

In the flexible content management system of AnQiCMS, site operators often need to display some key background configuration information in the website template according to business needs.Among the settings such as 'Background Independent Domain', it not only concerns the security of the system, but may also need to be displayed on the website front-end in certain scenarios, such as being used as a quick access entry for internal personnel, or for information explanation on specific pages. Today, let's delve into how to cleverly call and display the independent domain you have configured in the AnQiCMS template.###

2025-11-07

How to display the AnQiCMS built-in system language package switch feature on the front page?

AnQi CMS provides a flexible mechanism to allow your website to better serve users in different languages around the world.When you want to implement language switching on the front page, the tags and backend configuration built into AnQiCMS can well meet this need.Understanding AnQiCMS language package mechanism First, we need to clarify the concept of "language package" in AnQiCMS.The system language package built into AnQiCMS is mainly responsible for switching the website backend interface and the language of the**system built-in prompts, labels, etc.**on the front-end page.

2025-11-07

How to display the custom parameter list in the article content on the front page?

AnQiCMS as an efficient and customizable content management system provides powerful content model features, allowing us to add various custom fields to articles according to different business needs.These custom parameters not only make the article content more rich and structured, but also allow for personalized display on the front page, greatly enhancing the flexibility and user experience of the website.Today, let's delve into how to flexibly display these custom parameter lists in the AnQiCMS front page.

2025-11-07

How to truncate the title or abstract of an article and display it with an ellipsis?

In website content operation, titles and summaries are important elements to attract visitors to click and learn more details.Especially on list pages, recommendation positions, or the homepage, the limited space requires us to refine and cut these contents.To maintain the neatness and aesthetics of the page while fully conveying the core information, it is a common optimization strategy to truncate overly long article titles or summaries and end them with an ellipsis "..."}AnQiCMS (AnQi CMS) provided us with flexible and powerful tools to meet this requirement.

2025-11-07

How to use logical tags like `if` and `for` in templates to control conditional and repeated display of content?

In website content management, displaying dynamic and diverse content is the key to improving user experience and website attractiveness.AnQiCMS (AnQiCMS) provides a powerful template system, drawing inspiration from the Django template engine syntax, allowing you to easily control the display of content through logical tags.Among them, the `if` tag is used for conditional judgment, while the `for` tag is used for loop iteration, they are the foundation for building flexible and variable web pages.

2025-11-07

How to safely display rich text content containing HTML tags on the front-end page?

In website operation, we often need to display rich content that includes images, links, bold text, and so on, which is known as rich text content.But it is a practical and careful task to safely display these rich text with HTML tags on the front-end page.AnQi CMS as an efficient content management system, fully considers this point, and provides us with a clear solution.

2025-11-07