How to use the `pagination` tag to generate a page navigation that conforms to user habits for articles or product lists?

Calendar 👁️ 63

In website operations, how to allow users to easily browse a large amount of content and find information that interests them is a crucial topic.Especially on pages like article lists and product displays, reasonable pagination navigation not only improves user experience but is also an indispensable part of search engine optimization (SEO).AnQiCMS (AnQiCMS) fully understands this and therefore provides powerful and flexiblepaginationTags, help us easily generate professional and user-friendly pagination navigation for website content.

Let's delve deeper into how to utilize it in AnQi CMS.paginationTag, to create a smooth pagination experience for website content.

UnderstandingpaginationThe core role of tags

First, it needs to be clear.paginationThe tag itself is not used to retrieve articles or product data, it is more like a 'page navigation generator'. Its main responsibility is to generate page navigation based on the context of the current page (for example, byarchiveListortagDataListThe list data obtained by the tag, calculate and render a pagination navigation structure containing home page, previous page, specific page number, next page, and end page. This means that when usingpaginationBefore the label, we must first call the corresponding list label in the template and clearly indicate that pagination is required.

Under normal circumstances, we would cooperatearchiveListlabel (ortagDataList/commentListTags that support pagination can be usedpaginationWhen you arearchiveListsettype="page"Specify the parameter and specifylimitWhen the number of items displayed per page is set, AnQi CMS will automatically prepare all the data required for pagination, and this data will be used aspaginationLabel input.

paginationthe parameters and internal structure of the tag

paginationThe tag accepts a main parametershowIt is used to control the maximum number of page buttons displayed in pagination navigation. For example, setshow="5"It will display up to five page numbers near the current page (excluding the first page, last page, previous page, and next page).This parameter is very useful, it can help us avoid the pagination navigation becoming too long when there are too many page numbers.

When you use{% pagination pages with show="5" %}This way when calling the tag,pagesThe variable will carry all the details about pagination. Thispagesobject contains a series of useful properties, such as:

  • TotalItemsTotal number of entries in the list.
  • TotalPages: Total number of pages.
  • CurrentPage: Which page is currently being accessed.
  • FirstPageA object that contains the home page name and link, usually used for the 'Home' button.
  • LastPageA object that contains the end page name and link, usually used for the 'End' button.
  • PrevPageA object that contains the name and link of the previous page, available when it is not the first page.
  • NextPageAn object that contains the name and link of the next page, available when it is not the last page.
  • Pages: This is an array that contains all the middle page number objects, each of which also includesName(page number),Link(Page link) andIsCurrent(Whether the current page, a boolean value that can be used to highlight the current page style).

With these rich properties, we can flexibly build various layouts and styles of pagination navigation.

Practical exercise: Build a pagination navigation that conforms to user habits.

Imagine that we are building a list page of articles for a news website, hoping to display 10 articles per page and have a pagination navigation that can intelligently display the 5 page numbers around the current page. Here is a complete template code example:

{# 首先,我们调用 archiveList 标签获取文章列表数据,并指明分页类型为 "page" #}
<div>
    {% 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>
                <footer>
                    <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                    <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>阅读量:{{item.Views}}</span>
                </footer>
            </article>
        {% empty %}
            <p>暂时没有文章内容。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 紧接着,在 archiveList 标签的下方,我们就可以使用 pagination 标签来生成分页导航了 #}
    <div class="pagination-nav">
        {% pagination pages with show="5" %}
            <ul>
                {# 首页按钮 #}
                <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 数组 #}
                {% 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>
            <p class="summary">总共 {{pages.TotalItems}} 条内容,分 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页。</p>
        {% endpagination %}
    </div>
</div>

In this code, we first usearchiveListTag to get article data. Notice thattype="page"andlimit="10"settings, which tell the Anqi CMS that we want to display by page, 10 items per page. Then, after the list content is displayed, we callpaginationLabel and assign its result topagesVariable, and pass throughshow="5"Control the number of pages displayed.

InpaginationWe make use of it within the tagpagesThe properties of the variable are constructed in order to build pagination navigation. For example,pages.FirstPage.LinkProvided the link to the home page,pages.PrevPageIt exists only when the current page is not the first page, which makes the 'Previous page' button smartly display or hide. The core is to traversepages.Pagesthe array to generate specific page number buttons, and to utilizeitem.IsCurrentAdd to the current pageactiveclass, which is convenient for highlighting through CSS. Finally, we also demonstrated how to utilizeTotalItems/TotalPagesandCurrentPageto display the summary information of the current pagination.

Advanced techniques and precautions

  • SEO optimization and pseudo-static:SafeCMS is very friendly to SEO, after configuring the URL rules under "Function Management" and "URL Rules" in the background (for example, using{module}-{id}.htmlor{catname}-{page}.htmlthis kind of pattern),paginationThe generated links will automatically follow these rules. This means that your pagination links will be static, making them easier for search engines to crawl and index, thereby improving your website's SEO performance.
  • Dynamic filtering and pagination of search results:Whether the user filters through categories, tags, or enters keywords in the search box,paginationLabels can intelligently read the query parameters of the current URL and automatically add these parameters when generating pagination links. You

Related articles

How to display the friend link list in the website background configuration of Anqi CMS?

In website operation, friendship links are an important link to enhance website weight, increase traffic, and improve user experience.AnQiCMS (AnQiCMS) provides us with a convenient way to manage and display these links.How can the list of friend links configured on the back-end be displayed on the website front-end?This is actually simpler than imagined, mainly involving two steps: backend configuration and frontend template invocation. ### Step 1: Configure the友情链接 in the background Firstly, we need to add and manage the friendship links in the Anq CMS background management system.According to system design

2025-11-09

How to use the `guestbook` tag to build and display a dynamic guestbook form on the front page?

In AnQiCMS, building a functional message form is an important way to interact effectively with users, collect feedback, or obtain potential customer information.It is pleasing that with its powerful template tag system, especially the `guestbook` tag, we can easily create and display a dynamic and flexible guestbook form on the front page without writing complex backend code.The core of flexibly building a message form

2025-11-09

How to retrieve and display all the detailed content of a single page, including the slide group image, using the `pageDetail` tag?

In Anqi CMS, a single page is an indispensable part of the website structure, commonly used to display 'About Us', 'Contact Information', 'Service Introduction', etc., which are relatively fixed and do not require frequent updates.For these pages, we usually want to be able to flexibly control the way content is displayed, including text, images, and even slide group images.The `pageDetail` tag is born for this, it allows us to easily retrieve and display all the detailed content of a single page.###

2025-11-09

How does the `pageList` tag in Anqi CMS display all single page lists and exclude specific pages?

AnQi CMS is a flexible and efficient content management system that provides strong support for our website operations, whether it is publishing articles, managing products, or creating various single-page applications, it shows great proficiency.Today, let's talk about a very practical skill when using Anqi CMS to manage single-page applications: how to display all single pages through the `pageList` tag while also accurately excluding specific pages that we do not want to display.In daily website operations, we often create some single-page pages such as "About Us", "Contact Information", "Privacy Policy" and so on

2025-11-09

What are some practical scenarios for using the `if/else` logical judgment tags in AnQi CMS to control content display conditions?

In AnQi CMS template design, the `if/else` logical judgment tag is an extremely powerful tool that endows the website content with the vitality of dynamic display.By flexibly using this tag, we can intelligently control the display and hiding of elements on the page based on different conditions, thereby providing users with more accurate and personalized browsing experiences, and also greatly improving the operational efficiency of the website.Imagine if your website needs to display different content for different scenarios or if certain information is only visible under specific conditions

2025-11-09

How to implement diverse data layout and display with the `for` loop tag in AnQi CMS?

How to present information in a more rich and attractive way during website content operation is the key to improving user experience and site activity level.AnQiCMS (AnQiCMS) provides us with the tool to achieve this goal with its flexible content model and powerful template engine.Among them, the `for` loop iteration tag is the essential core tool for us to perform diverse formatting and display.Imagine your website is not just a static pile of articles, but can intelligently present lists of articles, product galleries, category navigation, user comments, and even custom parameters based on different scenarios

2025-11-09

How to format a timestamp into a readable date and time using the `stampToDate` tag in AnQi CMS?

In website operation, the display of time information is crucial. Whether it is the publication date of articles, the update time of products, or the submission time of comments, a clear and easy-to-read date and time format can greatly enhance the user experience.The original timestamp is machine-friendly, but it is cryptic to ordinary visitors.Fortunately, AnQiCMS (AnQiCMS) provides a very convenient template tag——`stampToDate`, which can easily format timestamps into the date and time we are familiar with.### `stampToDate` label

2025-11-09

How to use the `system` tag to retrieve and display the global information of a website, such as the website name, Logo, and filing number?

It is crucial to maintain the consistency of brand image and the accuracy of information in website operation.AnQi CMS is an efficient content management system that provides us with a convenient way to manage and display these core information.Today, let's delve into how to use the `system` tag of Anqi CMS to easily obtain and display global information on the website template, such as the website name, Logo, and filing number.

2025-11-09