How to list all documents under a specific tag in AnQi CMS template and support pagination?

Calendar 👁️ 59

In a content management system, effectively organizing and displaying articles is the key to improving user experience.When content is categorized through tags, we often need to list all articles under a specific tag on a single page, and to maintain the cleanliness and loading speed of the page, pagination functionality becomes indispensable.AnQi CMS provides powerful and flexible template tags, making this requirement easy to achieve.

This article will introduce how to combine in the AnQi CMS template,tagDataListTags andpaginationTags, elegantly list all documents under specific tags and support comprehensive pagination.

Get to know the core tools:tagDataListandpaginationTag

To implement the list and pagination under a specific tag, we mainly use two powerful template tags:tagDataListandpagination.

  1. tagDataListTags:This tag is specifically used to retrieve the document list associated with a specific tag.It is very flexible and can be used to filter and control the documents obtained through various parameters.type="page"It will tell the system to prepare pagination data for this list.

    Common parameters overview:

    • tagId: Specify the document under which label to retrieve. Usually on the label detail page, the system automatically identifies the current label's ID; on other pages, you can manually specify a label ID.
    • moduleIdIf your website has different content models such as articles and products, you can use this parameter to specify which model's documents to retrieve, for examplemoduleId="1"(Assuming the ID of the article model is 1).
    • limit: Set the number of documents displayed per page.
    • order: Define the sorting method of documents, such asorder="id desc"(Sorted by ID in descending order, i.e., the most recent published),order="views desc"(Sorted by views in descending order).
    • type="page"This is the key to implementing pagination! It will maketagDataListReturn a paginated dataset forpaginationlabel usage

    tagDataListThe document data obtained will be an array object, usually namedarchives(Or any name you like). Each item in the arrayitemincludes detailed information about the document, such asitem.Id/item.Title/item.Link/item.Description/item.Thumb(thumbnail),item.Views(Views) anditem.CreatedTime(Publish time) etc.

  2. paginationTags:This tag is responsible for generating pagination navigation links. It needs to receivetagDataListprepared pagination data. ThroughpaginationYou can easily generate "Home", "Previous page", "Next page", "End page" and a series of page number links.

    Common parameters overview:

    • show: Controls the maximum number of page link navigations displayed, for exampleshow="5"Displays the maximum of 5 page numbers around the current page.

    paginationA tag provides an object containing pagination information, usually namedpages. This object includes such aspages.TotalItems(Total number of documents),pages.TotalPages(Total number of pages),pages.CurrentPage(current page) and the objects pointing to each pagination link (pages.FirstPage/pages.PrevPage/pages.NextPage/pages.LastPageandpages.Pages)

Practice operation: Build a list of specific tag documents with pagination

Suppose we are building a tag detail page, hoping to display all articles under the tag and support pagination.

First step: Obtain the current tag information (optional but recommended)At the top of the page, we might want to display the name and description of the current tag. This can be achieved bytagDetailthe tag.

{# 假设这是 tag/list.html 或 tag/detail.html 模板 #}
{% tagDetail tagInfo with name="Title" %}
<h1>{{ tagInfo }}</h1>
{% tagDetail tagDescription with name="Description" %}
<p>{{ tagDescription }}</p>

Second step: usetagDataListGet paginated document dataNext, we will usetagDataListLabel to retrieve the document list under this label. The key is to settype="page"andlimitParameters, which will prepare for pagination

{# 使用 tagDataList 获取文档列表,并将 type 设置为 "page" 以支持分页 #}
{% tagDataList archives with type="page" limit="10" %}
    <ul class="document-list">
        {% for item in archives %}
        <li>
            <a href="{{ item.Link }}">
                <h3>{{ item.Title }}</h3>
                {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
                {% endif %}
                <p>{{ item.Description }}</p>
                <div class="meta">
                    <span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    <span>浏览量: {{ item.Views }}</span>
                </div>
            </a>
        </li>
        {% empty %}
        <p>该标签下暂时没有找到任何文档。</p>
        {% endfor %}
    </ul>
{% endtagDataList %}

Here we iteratedarchivesOver each document in the variableitemAnd displayed the title, thumbnail, introduction, publish date, and view count information.{% empty %}Tags are used to display friendly prompts when the list is empty.

Third step: usepaginationBuild pagination navigationNow, the document list is ready, and we need to add pagination navigation.paginationThe tag needs to be placedtagDataListAfter the tag, so that it can access heretagDataListGeneratedpagesObject.

{# 分页导航区域,假设 pages 变量由上面的 tagDataList 标签自动填充 #}
<div class="pagination-nav">
    {% pagination pages with show="5" %}
    <ul class="page-links">
        {# 首页链接 #}
        <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>
        {% endif %}
        {# 尾页链接 #}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
            <a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
        </li>
    </ul>
    <div class="page-info">
        共 {{ pages.TotalItems }} 篇文章,{{ pages.TotalPages }} 页,当前第 {{ pages.CurrentPage }} 页。
    </div>
    {% endpagination %}
</div>

We use here,pagesThe various properties of the object are used to build a complete pagination navigation.pageItem.IsCurrentCan be used to highlight the current page number,pages.PrevPageandpages.NextPageThe condition ensures that the corresponding links are displayed only when there is a previous page/next page.

Complete example code

Integrate the above code snippet together, and a page with a list of documents with specific tags and pagination functionality is completed:

”`twig {% extends ‘base.html’ %} {# Inherit the base template to ensure the existence of common elements such as header, footer, etc. #}

{% block content %} {# Define content area #}

{# Part 1: Display the name and description of the current tag #}

{% tagDetail tagInfo with name="Title" %}

Related articles

How to get the current page number, total number of pages, and home/last page links for the `pagination` tag?

AnQiCMS (AnQiCMS) is a powerful content management system that provides flexible and diverse ways to display content when building a website.Among them, the pagination function is crucial for list pages with a large amount of content, as it not only improves the user experience but also optimizes the website performance.Proficiently use the `pagination` tag, which can help us accurately control the display logic of pagination, thereby creating a more user-friendly and professional website.

2025-11-08

How to create a customizable pagination component for the document list in Anqi CMS template?

It is crucial to display and manage document lists efficiently when building a content-rich website.Especially for sites with a large amount of content, a well-designed, feature-complete pagination component can not only greatly improve user experience but also optimize the website's SEO performance, helping search engines to better crawl and index content.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag features, allows us to easily create highly customizable pagination components for document lists.

2025-11-08

How to judge whether the comment is under review and display it conditionally using the `commentList` tag?

In website operation, comments are an important element in enhancing user interaction and community vitality.However, it is an indispensable link to review the comments submitted by users to ensure the health and quality of the website content.How can we flexibly display these comments in AnQi CMS, especially when they are still in the review stage, which has become a concern for many operators.It's good that AnQi CMS template tag system provides us with strong control, especially the `commentList` tag, which can help us easily implement conditional display of comments.

2025-11-08

How to display a document's comment list in Anqi CMS template, including reply and pagination features?

In Anqi CMS, add a comment list to the document content and enable it to have reply and pagination functions, which can greatly enhance the user interaction of the website.Users can express their opinions and discuss specific documents, which not only enriches the content ecosystem but also brings more vitality to the website. ### One: Displaying Comment Lists: The Foundation of Interaction To display comments on a document page, it mainly relies on the `commentList` tag built into Anqin CMS.This tag helps us easily get the comment data associated with the current document. First

2025-11-08

How to display document, category, or single page associated image groups (such as Banner galleries) in Anqi CMS template?

At the time of building a website, exquisite image sets, such as carousel banners, are important elements to attract visitors' attention and display core content.AnQiCMS (AnQiCMS) provides flexible and powerful template functions, allowing you to easily display these groups of images associated with documents, categories, or single pages on the website.This article will delve into how to call and display these image groups in Anqi CMS templates, helping you better utilize visual content to enhance the attractiveness of your website.---###

2025-11-08

What is the practical use of the `dump` filter in AnQi CMS template debugging?

During the development and maintenance of Anqi CMS templates, we often encounter situations where some data cannot be displayed correctly or the variable structure does not match the expected one.How can one quickly and effectively find the source of the problem, which is a challenge facing every template developer.Fortunately, AnQi CMS provides an extremely useful tool—the `dump` filter, which can help us penetrate the true appearance of variables in the template like X-ray.What is the `dump` filter?

2025-11-08

How to use the `stringformat` filter to format a floating-point number as a string with two decimal places?

In website content display, accurate and unified number presentation is crucial for user experience.For example, displaying product prices on e-commerce websites or presenting statistical percentages in data reports may result in excessively long decimal places if floating-point numbers are displayed without processing, which may appear unprofessional and untidy.AnQi CMS as an efficient content management system provides powerful template functions, among which the `stringformat` filter is a powerful tool to solve this problem.

2025-11-08

How to define the `stringformat` filter using Go's `fmt.Sprintf` format?

In AnQi CMS template design, the flexibility of data display is a key aspect that template developers highly value.The system is built-in with multiple filters (Filters) to process and format variables.Among them, the `stringformat` filter is a versatile tool that allows us to control the output format of any type of data with the powerful format definitions of the Go language `fmt.Sprintf` function, whether it is numbers, strings, or more complex data structures, all can be displayed in the expected style.What is

2025-11-08