How to use the `pagination` tag to create pagination for the document list under the specified Tag?

Calendar 👁️ 61

As an experienced website operations expert, I am well aware of the importance of content organization and user experience in today's digital world.In an efficient and feature-rich system like AnQiCMS, how to present a vast amount of content to users in the most user-friendly way while also considering search engine optimization is a topic we need to continuously think about and practice.Today, let's delve into a practical and powerful combination in Anqi CMS: how to use it cleverlytagDataListLabel collaborationpaginationThe tag, generates accurate and smooth pagination for the document list under the specified Tag.

AnQi CMS, with its high-performance architecture based on the Go language, flexible content model, and excellent SEO tools, has become the preferred choice for many enterprises and content operation teams.It not only provides core content types such as articles and products, but also helps us classify and associate content more granularly through powerful Tag features.

Understand the Tag tag function of Anqi CMS.

In AnQi CMS, the Tag label is not just a simple keyword, but also a powerful way of organizing content.By adding tags to the document, we can gather related content scattered across different categories into a "mini thematic page" centered around a specific theme.For example, an article about 'website performance optimization' may belong to the 'SEO skills' category, and can also be tagged with 'front-end technology', 'Go language development', and so on.Users can quickly find all documents associated with a tag while browsing a tag page, greatly enhancing the efficiency of content discovery and the user's browsing experience.

Our CMS provides an independent page template for tags, usually locatedtag/list.htmlortag_list.htmlThese pages are the stage where we display the document list under a specific Tag.

Core function:tagDataListThe charm of tags

Show documents on these tab pages,tagDataListTags are our core tool. As the name implies, it is specifically used to retrieve the document data list associated with a certain Tag.It can intelligently retrieve all articles or products containing the specified Tag ID that we specify.

UsetagDataListWhen dealing with tags, we usually pay attention to the following important parameters:

  • tagIdThis specifies the key parameter to retrieve the document list under which Tag we want.If you are currently on a Tag detail page, AnQi CMS will intelligently automatically identify and use the Tag ID of the current page, and you do not even need to explicitly specify it.
  • moduleIdIf you want to display only specific content models (such as article models or product models) under the document, you can filter it through this parameter.
  • order: The document sorting method. You can display content based on the publication time(id desc), views (views desc)or custom sorting in the background(sort desc) to meet different content strategies.
  • limitThis controls the number of documents returned per query. This is particularly important when used with pagination tags, as it determines how many documents are displayed per page.
  • type="page":This is the key to implementing pagination functionality!When we willtypethe parameter to"page"then,tagDataListWill no longer just return a fixed number of lists, but will prepare complete page numbers and pagination data for subsequentpaginationtags.

tagDataListThe tag will store the obtained document list in a traversable variable, for examplearchives. In the template, we can iterate througharchivesto get each document'sId/Title/Link/Description/CreatedTimeProvide detailed information and display as needed.

The magic of pagination:paginationTag

When the number of documents under a Tag reaches dozens or even hundreds, loading them all at once not only affects page performance but also makes the user feel overwhelmed. At this time,paginationLabels have played their magical role. It can generate a complete pagination navigation including home page, previous page, specific page number, next page, and last page based on the provided data.tagDataList提供的数据,自动生成一个包含首页、上一页、具体页码、下一页和末页的完整分页导航。

paginationThe common parameters of the tag are:

  • showIt is used to control how many specific page number links are displayed in the pagination navigation. For exampleshow="5"It will display up to 5 page numbers before and after the current page.

paginationThe tag creates a namedpagesThe object (of course, you can also define its variable name), this object contains all the information needed for pagination:

  • TotalItems: Total number of documents.
  • TotalPages: Total number of pages.
  • CurrentPage: The page number of the current user.
  • FirstPage/LastPage/PrevPage/NextPageThese are page objects that provide corresponding links(Link) and display names(Name), allowing us to easily build navigation.
  • PagesThis is an array that contains all the page number links that need to be displayed.By traversing this array, we can dynamically generate the middle page navigation.Each element in the array is also an object, containingName(page number),Link(Page link) andIsCurrent(Whether it is the current page, used for style highlighting).

Practical exercise:tagDataListwithpaginationThe Perfect Combination

Now, let's look at a specific template code example to seetagDataListandpaginationHow they work together. This code is usually placed in yourtag/list.htmlortag_list.htmltemplate file.

Assuming we want to display an article list under a tag, showing 10 articles per page, and providing pagination navigation with up to 5 page numbers:

`twig {# First, get the document list under the specified Tag.} On the Tag detail page, tagId is usually automatically identified and does not require explicit setting. type=“page”is key, it tells the system to prepare for pagination. limit="10" sets the number of documents displayed per page to 10.#} {% tagDataList archives with type=“page” limit=“10” order=“id desc” %}

<div class="tag-document-list">
    {% for item in archives %}
    <article class="document-item">
        <h2><a href="{{item.Link}}">{{item.Title}}</a></h2>
        <div class="meta-info">
            <span>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            <span>浏览量:{{item.Views}}</span>
            {# 如果需要显示文档分类,可以结合 categoryDetail 标签 #}
            <span>分类:<a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></span>
        </div>
        <p>{{item.Description}}</p>
        {% if item.Thumb %}
            <div class="thumbnail">
                <a href="{{item.Link}}"><img src="{{item.Thumb}}" alt="{{item.Title}}"></a>
            </div>
        {% endif %}
        <a href="{{item.Link}}" class="read-more">阅读更多 &raquo;</a>
    </article>
    {% empty %}
    {# 当Tag下没有文档时,显示此内容 #}
    <p class="no-content-message">当前标签下暂无相关文档。</p>
    {% endfor %}
</div>

{# 接着,使用 pagination 标签生成分页导航。
   show="5" 表示最多显示5个页码链接(不含首页、尾页、上下页)。 #}
<nav class="pagination-navigation">
    {% 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 %}

        {# 中间页码链接列表 #}
        {% for pageItem in pages.Pages %}
        <li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
            <a href="{{pageItem.Link}}">{{pageItem.Name}}</a>
        </li>
        {% endfor %}

        {# 下一页链接,仅在存在时显示 #}
        {% if pages.NextPage %}
        <li class="page-item">
            <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        </li>

Related articles

How to combine the `commentList` tag with the `pagination` tag to implement pagination of comment content?

Hello! As an experienced website operations expert, I am very willing to delve into how to巧妙ly combine `commentList` and `pagination` tags in AnQiCMS to achieve the pagination display of comment content, making user interaction smoother and more orderly.In today's content-driven era, user comments are not only a symbol of website vitality but also an important embodiment of content value.However, if a popular article accumulates a massive amount of comments, loading them all at once would undoubtedly put a huge burden on the page, severely affecting user experience. At this time

2025-11-07

How does the `archiveList` tag work with the `pagination` tag to implement pagination when using the `type="page"` mode?

In AnQiCMS content management system, efficiently displaying a large amount of content and ensuring a good user experience and search engine optimization is the key to successful operation.Among these, the pagination display of the content list undoubtedly plays a core role.

2025-11-07

How to get and display the current page number in AnQiCMS template?

## The Art of Pagination Mastery: Easily Get the Current Page Number in AnQiCMS Templates As an experienced website operations expert, I am well aware of the importance of an efficient content management system for the vitality of a website.AnQiCMS with its high-performance architecture based on the Go language and flexible template mechanism has become the preferred choice for many small and medium-sized enterprises and content operation teams.In daily operations, we often need to display pagination information on list pages, search result pages, and other scenarios, where obtaining and displaying the current page number is a fundamental and core requirement. Today

2025-11-07

What do `pages.TotalItems` and `pages.TotalPages` represent in pagination tags, and what scenarios can they be used in?

As an experienced website operations expert, I know that a powerful and flexible content management system is crucial for the success of a website.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and rich features, providing great convenience for content operators.Today, with the content of websites becoming increasingly rich, how to efficiently display and manage this content while providing an excellent user experience is a topic that every operator must face.The pagination mechanism is one of the core means to solve this problem.Today, we will deeply analyze the two key variables in the Anqi CMS pagination tag

2025-11-07

Does AnQiCMS support custom pagination URL structure for its pagination tag? What is the specific usage of the `prefix` parameter?

AnQiCMS Pagination Tag and Custom URL Structure: Deep Analysis of `prefix` Parameter As an experienced website operations expert, I know how important it is to have a clear, SEO compliant, and user-friendly URL structure for a website.How to flexibly control pagination links, especially in content management systems, is a common concern for operators.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, providing website administrators with a great degree of freedom through its powerful template engine and pseudo-static features. Today

2025-11-07

How to transform the traditional pagination navigation in AnQiCMS into 'Load More' or 'Infinite Scrolling' effect?

As an experienced website operation expert, I am well aware that user experience has become one of the key factors for the success of a website in today's rapidly changing internet environment.The traditional pagination navigation, although clear in function, often causes unnecessary sense of disconnection and waiting time while users browse the content.The effect of 'Load More' or 'Infinite Scrolling' can greatly enhance the user's continuous reading experience, reduce the bounce rate, and increase user stickiness.

2025-11-07

What do `pages.PrevPage` and `pages.NextPage` return when there are no previous or next pages, and how can template errors be avoided?

As an experienced website operation expert, I have accumulated rich experience in the practice of AnQiCMS.Today, let's delve deeply into a common but crucial issue in template development: what `pages.PrevPage` and `pages.NextPage` return when there is no previous or next page, and how we can cleverly avoid the template errors caused by this, ensuring the stability of the website's frontend and the smoothness of the user experience.

2025-11-07

Will the AnQiCMS pagination tag generate a URL that automatically includes all the filter parameters on the current page (such as `q`)?

AnQiCMS (AnQiCMS) is an enterprise-level content management system that deeply understands the core needs of content operation and SEO, and has fully considered user experience and the optimization of search engine optimization from the beginning of its design.About whether the URL generated by the AnQiCMS pagination tag automatically includes all the filter parameters on the current page (such as `q`)?This question has an affirmative answer, and this is exactly where AnQiCMS demonstrates its intelligence and convenience in detail.

2025-11-07