How to get and paginate the display of all relevant documents under a specific `tagDataList` tag?

Calendar 👁️ 58

When managing content in AnQi CMS, tags (Tag) are an important tool for organizing and categorizing information.It can not only help users quickly find relevant content, but also significantly improve the internal link structure and SEO performance of the website.When it is necessary to display all relevant documents under a specific tag and manage pagination,tagDataListTags have become an indispensable core function.

This article will delve into how to efficiently utilizetagDataListTo retrieve and paginate the documents under a specific tag, thereby optimizing the content presentation and user experience of the website.

1. UnderstandingtagDataListThe role of the tag

tagDataListThe tag is a powerful and flexible component in AnQi CMS template engine, its main function is to retrieve and list all documents associated with the specified tag (Tag).These documents can be articles, products, or even other custom model content, as long as they are assigned the same tags.

The core value of this tag lies in its ability to provide highly customized content lists and support pagination, which is crucial for building tag archive pages, related content recommendation blocks, or any scenario that requires content aggregation by tag.

tagDataListThe basic usage format is as follows:{% tagDataList 变量名称 with 参数... %}

Among them,变量名称It is the name you customize for the document list you obtain, and you can traverse and display it in the template later.

2. Retrieve documents under a specific tag

To retrieve documents under a specific tag,tagDataListThe tag needs to know the identifier of the target tag, that is,tagId.

  • Use on the tag detail page:If you are editing a label detail page template (usuallytag/detail.htmlortag/list.html)tagDataListthe label will automatically identify the current pagetagId, at this point you can omit tagIdParameters. The system will default to retrieving all documents associated with the current tag.
  • Specify the tag on other pages:If you want to display documents under a specific tag on the homepage, category page, or any other page, you need to manually go throughtagId="X"parameters to explicitly specify the tag ID (whereXIs the unique identifier of the tag in the background).

excepttagId,moduleIdThe parameter is also very useful. If you want to display only the documents associated with the tag under a specific model (such as an article model or a product model), you can do so bymoduleId="1"(Article model ID is 1) ormoduleId="2"(Product model ID is 2) to further filter.

Here is a simple code example showing how to get the first 10 documents under a certain tag (without pagination):

{# 假设我们想获取ID为5的标签下的所有文章(模型ID为1) #}
{% tagDataList archives with tagId="5" moduleId="1" limit="10" order="id desc" %}
    {% for item in archives %}
    <div class="document-item">
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description|truncatechars:100 }}</p>
        <div class="meta">
            <span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            <span>浏览量:{{ item.Views }}</span>
            {# 可以在此调用分类信息 #}
            <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
        </div>
        {% if item.Thumb %}
        <a href="{{ item.Link }}">
            <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="document-thumb">
        </a>
        {% endif %}
    </div>
    {% empty %}
    <p>该标签下暂无相关文档。</p>
    {% endfor %}
{% endtagDataList %}

In the above code,itemIsforThe current document object in the loop, it contains the document'sId/Title/Link/Description/CreatedTime/Views/Thumb/CategoryIdCommon fields. You can freely call these fields according to your needs to enrich the display content of the document.orderThe parameter is used to specify the sorting method of the document, for example.id descIndicates sorting by ID in reverse order (newest release),views descwhich indicates sorting by view count in reverse.

3. Implement document pagination display

To implement pagination for the tag document list, we need to adjusttagDataListtagstype="page"Parameters, and combinepaginationTags to render pagination navigation.

type="page"The parameter tellstagDataListLabel, we need a pageable dataset that will calculate the total number of pages and the data for the current page based onlimitthe parameters (how many items per page) and the current page number.

Next,paginationTags are responsible for generating various links and pagination information required for pagination navigation. It includesshowParameters can control the maximum number of pagination buttons displayed in pagination navigation.

Below is a combinationtagDataListandpaginationExample code to implement pagination:

{# 假设仍在标签详情页,tagId和moduleId可省略或根据需要指定 #}
{% tagDataList archives with type="page" limit="10" order="id desc" %}
    <div class="tag-document-list">
        {% for item in archives %}
        <div class="document-card">
            <a href="{{ item.Link }}" title="{{ item.Title }}">
                {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="card-thumb">
                {% endif %}
                <h4 class="card-title">{{ item.Title }}</h4>
                <p class="card-description">{{ item.Description|truncatechars:120 }}</p>
            </a>
            <div class="card-meta">
                <span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>阅读量: {{ item.Views }}</span>
            </div>
        </div>
        {% empty %}
        <p>该标签下暂无文档。</p>
        {% endfor %}
    </div>

    {# 分页导航区域 #}
    <div class="pagination-container">
        {% pagination pages with show="7" %}
        <ul class="pagination-list">
            {# 首页链接 #}
            {% if pages.FirstPage %}
            <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.FirstPage.Link }}" class="page-link">{{ pages.FirstPage.Name }}</a>
            </li>
            {% endif %}

            {# 上一页链接 #}
            {% if pages.PrevPage %}
            <li class="page-item">
                <a href="{{ pages.PrevPage.Link }}" class="page-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 }}" class="page-link">{{ pageItem.Name }}</a>
            </li>
            {% endfor %}

            {# 下一页链接 #}
            {% if pages.NextPage %}
            <li class="page-item">
                <a href="{{ pages.NextPage.Link }}" class="page-link">{{ pages.NextPage.Name }}</a>
            </li>
            {% endif %}

            {# 尾页链接 #}
            {% if pages.LastPage %}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.LastPage.Link }}" class="page-link">{{ pages.LastPage.Name }}</a>
            </li>
            {% endif %}
        </ul>
        <div class="pagination-info">
            总计 {{ pages.TotalItems }} 条文档,共 {{ pages.TotalPages }} 页,当前第 {{ pages.CurrentPage }} 页。
        </div>
        {% endpagination %}
    </div>
{% endtagDataList %}

In pagination code,pagesThe variable contains all pagination information, for examplepages.TotalItems(Total number of documents),pages.TotalPages(Total number of pages),pages.CurrentPage(current page number) etc. The most commonly used ispages.Pagesan array that contains all the page numbers to be displayedpageItemobjects, eachpageItemand bothName(page number text),Link(Page link) andIsCurrent(Whether the current page) and other properties, convenient for us to build flexible pagination navigation.

4. Practical application and optimization suggestions

  • SEO Optimization:The tag archive page is an important entry for search engines to crawl and index website content. ThroughtagDataListDisplay pagination content, it can ensure that each tag has rich searchable content, and in conjunction with the built-in SEO features of Anqi CMS (such as pseudo-static, TDK settings), it can significantly improve the weight and ranking of the tag page in search engines.
  • User Experience:Clear pagination navigation allows users to easily browse a large number of tag content without having to load all documents at once, improving page loading speed and user satisfaction.Reasonably organize label categories,配合beautiful template design, so that users can find the information they need faster.
  • Content aggregation:Tags aggregate related thematic content scattered across different categories on the website, providing users with a completely new content discovery path.For example, a tag about "Go language" can aggregate all articles, tutorials, and related products related to Go language.
  • Flexibility: tagDataListSupport multiple sorting methods (by ID, view count, custom sorting, etc.), combined with richitemfields, you can display the most critical information according to your business needs.

Through proficiencytagDataListandpaginationTags, website operators can better organize and display website content, provide users with a better browsing experience, and also lay a solid foundation for search engine optimization.


Frequently Asked Questions (FAQ)

Q1:tagIdIs the parameter required? When can it be omitted? tagIdThe parameter is not always required. When you are on the tag detail page of the Anqi CMS backend (for exampletag/list.htmlortag/detail.htmltemplate)tagDataListWhen labeling, the system will automatically identify the tag ID of the current page, at which time it can be omittedtagIdThe parameter. However, if you want to display documents under a specific tag on the homepage, category page, or any other non-tag detail page, you need to manually go throughtagId="X"(where X is the ID of the target tag) to specify the target tag explicitly.

Q2: Besides the document title and link, what other document information can I display?UsetagDataListThe list of documents obtained (archivesEach variable containsitem) Contains very rich document information. In addition to

Related articles

How to use the `prevArchive` and `nextArchive` tags to navigate to adjacent documents in the article detail page?

In today's content-driven world, the user experience of the website article detail page is particularly important.When a reader is immersed in an excellent content, if they can navigate smoothly to related or adjacent articles, not only can it extend their stay on the website and increase the page views, but it can also indirectly optimize the search engine crawling and ranking through the internal link structure.AnQi CMS is an efficient and SEO-friendly content management system that fully considers these details and provides simple and intuitive template tags to help us easily achieve this function. Today

2025-11-07

How to implement hierarchical display and nested calling of the `categoryList` tag?

Building a clear and organized website navigation in AnQiCMS is crucial for improving user experience and website accessibility, especially when dealing with multi-level categories.The `categoryList` tag was created for this purpose, providing powerful features to help us flexibly display the hierarchical structure of categories and make fine-grained nested calls.

2025-11-07

How to retrieve the title, content, image, and custom fields of a specific document using the `archiveDetail` tag?

How to use the `archiveDetail` tag in AnQiCMS to finely control the display of document content?AnQiCMS as an efficient and flexible content management system, one of its core advantages lies in its powerful content display capabilities.For each independent article, product detail, or any other 'document' type of content on the website, we hope to fine-tune their display methods on the front page.This is the place where the `archiveDetail` tag really shines.

2025-11-07

How to precisely filter and display a document list with specific categories, models, or recommended attributes using the `archiveList` tag?

In AnQi CMS, the `archiveList` tag is the core tool for building dynamic content lists, allowing you to flexibly extract and display the content you want from the website's document library.Whether it is to display the latest articles under a specific category, or popular products under a certain content model, or special document topics with specific recommendation attributes, `archiveList` can help you accurately meet these needs through its rich parameter configuration.### Accurately locate content: Classification, Model and Recommendation Attributes First

2025-11-07

How to correctly configure the `pagination` tag to generate a functional pagination navigation on the list page?

In website content management, configuring a fully functional pagination navigation for the list page is a key factor in improving user experience and optimizing the website structure.AnqiCMS (AnqiCMS) provides a simple and powerful `pagination` tag, allowing developers to easily meet this need.To make the `pagination` tag generate the pagination navigation correctly on the list page, it is first necessary to understand its mechanism and the collaborative relationship with content list tags (such as `archiveList`).

2025-11-07

How to use the `stampToDate` tag to format a timestamp into a custom date and time format?

Good, I'm glad to deeply interpret the `stampToDate` tag of AnQiCMS, helping you easily control the time display on the website. --- ## Flexible Time Mastery: Customize Date and Time Format with AnQiCMS `stampToDate` Tag The way dates and times are displayed on a website often directly affects user experience and the clarity of information communication in content management.A concise and readable date format allows visitors to quickly understand the timeliness of the content. AnQiCMS

2025-11-07

How to dynamically generate page title, keywords, and description with the `tdk` tag and flexibly control whether to include the website name?

In website operation, the page title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, are the foundation of search engine optimization.They can not only help search engines understand the page content, but are also key factors to attract users to click.AnQiCMS (AnQiCMS) fully understands the importance of TDK, and through its powerful template tag system, especially the versatile `tdk` tag, makes dynamic generation and flexible control of page TDK easy and efficient.

2025-11-07

How to construct a website navigation with multi-level submenus and associated content using the `navList` tag?

When building a website, a clear and easy-to-use navigation system is crucial, as it directly affects whether users can quickly find the information they need and also influences how search engines understand the structure of the website.AnQiCMS provides a powerful `navList` tag, allowing us to flexibly build a navigation system with multi-level submenus and closely associate navigation items with website content.Next, we will delve into how to use the `navList` tag to create a set of multi-level navigation that is both beautiful and practical for your website.### Website Navigation Basics

2025-11-07