How to get and display the list of all documents under a specific Tag tag?

Calendar 👁️ 60

As a website operator who is well-versed in the operation of AnQiCMS, I fully understand the importance of efficient content management and optimization.Tags are one of the key elements for organizing content, enhancing user experience, and improving SEO performance.By using tags, we can not only provide readers with more precise content aggregation, but also help search engines better understand the structure of the website content.I will elaborate in detail on how to obtain and display the list of all documents under a specific Tag label in AnQiCMS.

The role and display requirements of Tag labels in AnQi CMS

In AnQiCMS, Tag is a flexible content classification method that goes beyond the hierarchical limitations of traditional classification, allowing content to be connected in a more relevant and thematic way.For example, an article about "AnQiCMS template creation" can be classified under "Technical Tutorial" and can also be tagged with "Template", "Front-end", "Go Language", and many other tags.This greatly enriches the relationship network between content, making it convenient for users to explore more related content based on their interests.

When we need to display all documents under a specific Tag label, we usually do so on the "Tag Details Page" (for exampletag/list.htmlOr other modules of the website (such as the popular tag articles in the sidebar, or the related tag articles at the bottom of the page) can be used. AnQiCMS provides special template tags to meet this need, the core of which istagDataList.

applytagDataListLabel to get document list

In the AnQiCMS template system,tagDataListIt is a key label used to get the document list associated with a specified Tag. Its design aims to implement this function in a concise and efficient manner.

To usetagDataListWe need to wrap it in aforloop because the tag returns an array of document (archive) objects. The basic usage is as follows:

{% tagDataList archives with tagId="1" type="page" limit="10" %}
    {# 循环遍历文档列表 #}
    {% for item in archives %}
        {# 文档信息的显示代码 #}
    {% endfor %}
{% endtagDataList %}

IntagDataListIn the tag, there are some important parameters that can help us accurately control the document list obtained:

  • tagId: This is the unique identifier for the target Tag. If you are on a Tag detail page (such astag/list.html), the system will usually automatically identify the current page.tagIdAt this point, you can omit this parameter. If you want to manually specify a document list for a Tag on another page, you need to explicitly settagId="X"where X is the Tag ID.
  • moduleId: If your website has multiple content models (such as articles, products), and you only want to retrieve Tag documents under specific models, you can setmoduleId="Y"to filter (for example,moduleId="1"It may represent an article model).
  • order: This parameter is used to control the sorting method of the document. Common options includeid desc(Sorted by latest release in reverse order),views desc(Sorted by views in reverse order),sort desc(Sorted by custom sorting in the background).
  • limit: Determines the maximum number of documents displayed in the list. If you want to display in paginated format, you can set the number of documents per page, for example,limit="10". If it is not a paged list, it can also be usedoffsetpattern, such aslimit="2,10"It means to get 10 data items starting from the 2nd one.
  • type: This parameter is very critical, it determinestagDataListthe return type. When set totype="page"It will return an object that supports pagination, which can be配合 used laterpaginationtag to implement pagination functionality. If set totype="list", it will only return the specifiedlimitnumber of documents without providing pagination information.
  • siteId: If you are using the AnQiCMS multi-site management feature and need to access Tag documents under other sites, you can specifysiteId="Z"to achieve.

tagDataListthe tags returned byarchivesA variable is an array where eachitemrepresents a document containing rich field information such as:Id(Document ID),Title(Document Title),Link(Document Link),Description(Document description),Thumb(thumbnail),CreatedTime(Creation time, to be usedstampToDateformatted),Views(Views) etc.

Actual template code example

Assuming we are editingtag/list.htmlA template, hoping to display the name of the current tag, as well as all articles under the tag, and provide pagination functionality.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>{% tdk with name="Title" siteName=true %}</title>
    <meta name="keywords" content="{% tdk with name="Keywords" %}">
    <meta name="description" content="{% tdk with name="Description" %}">
    <link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/style.css">
</head>
<body>
    {# 导航栏或其他页面头部 #}
    {% include "partial/header.html" %}

    <div class="main-content">
        <div class="container">
            {# 获取当前标签的详细信息,例如标签名称 #}
            {% tagDetail currentTag with name="Title" %}
            <h1>标签:{{ currentTag }} 下的文档</h1>

            <div class="tag-documents-list">
                {% tagDataList archives with type="page" limit="10" %}
                    {% for item in archives %}
                    <div class="document-item">
                        <a href="{{item.Link}}" class="document-link">
                            <h2>{{item.Title}}</h2>
                            {% if item.Thumb %}
                                <img src="{{item.Thumb}}" alt="{{item.Title}}" class="document-thumbnail">
                            {% endif %}
                            <p class="document-description">{{item.Description}}</p>
                        </a>
                        <div class="document-meta">
                            <span>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                            <span>浏览:{{item.Views}}次</span>
                            {# 获取文档所属分类的名称 #}
                            <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        </div>
                    </div>
                    {% empty %}
                    <p class="no-documents">当前标签下暂无任何文档。</p>
                    {% endfor %}

                    {# 列表分页代码 #}
                    {% pagination pages with show="5" %}
                        <nav aria-label="Page navigation" class="pagination-wrapper">
                            <ul class="pagination">
                                {% if pages.FirstPage %}
                                <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                                    <a class="page-link" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
                                </li>
                                {% endif %}

                                {% if pages.PrevPage %}
                                <li class="page-item">
                                    <a class="page-link" href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
                                </li>
                                {% endif %}

                                {% for p in pages.Pages %}
                                <li class="page-item {% if p.IsCurrent %}active{% endif %}">
                                    <a class="page-link" href="{{p.Link}}">{{p.Name}}</a>
                                </li>
                                {% endfor %}

                                {% if pages.NextPage %}
                                <li class="page-item">
                                    <a class="page-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
                                </li>
                                {% endif %}

                                {% if pages.LastPage %}
                                <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                                    <a class="page-link" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
                                </li>
                                {% endif %}
                            </ul>
                        </nav>
                    {% endpagination %}
                {% endtagDataList %}
            </div>
        </div>
    </div>

    {# 页脚或其他页面底部 #}
    {% include "partial/footer.html" %}
</body>
</html>

In this code, we first usetagDetailGet the title of the current Tag, as the main title of the page. Next,tagDataListStart withtype="page"method to get the document list, and set 10 documents per page.forInside the loop, we displayed the document title, link, thumbnail, description, publication time, views, and category. Finally, throughpaginationtags generated the complete pagination navigation.

Advanced usage and注意事项

In practice, you may have more complex requirements.For example, on the homepage or in the sidebar of the article detail page, display several of the latest documents under a specific hot Tag.tagIdandlimitAnd, totypeis set tolist:

{# 在首页或侧边栏显示Tag ID为5的最新5篇文档 #}
<h3>热门标签文章</h3>
<ul>
{% tagDataList hotArticles with tagId="5" type="list" limit="5" order="id desc" %}
    {% for item in hotArticles %}
    <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% empty %}
    <li>暂无热门标签文章。</li>
    {% endfor %}
{% endtagDataList %}
</ul>

Remember, AnQiCMS template tags are case-sensitive, be sure to write accurately according to the field names and parameter names provided in the documentation. By usingtagDataListAnd other auxiliary labels, you can build highly customized, rich in content, and easy-to-navigate web page.

Summary

AnQiCMS'tagDataListThe tag provides a powerful and flexible tool for website operators to retrieve and display document lists under specific Tag tags.Whether it is to build a dedicated tag archive page or display related content in other areas of the website, the tag can meet the diverse content aggregation needs through simple parameter configuration.

Related articles

How to display a list of tags and their details for all or specific articles on a website?

Hello!As an experienced CMS website operator, I fully understand your needs for the Tag feature in terms of content organization and optimization.Tags are an indispensable part of website content management, as they not only help users find relevant content faster, but also effectively improve the website's SEO performance.Below, I will elaborate on how to display the tag list and detailed information of all or specified articles on the AnQiCMS website.

2025-11-06

How to retrieve the custom field parameters defined in the content model and filter and display them?

As an experienced CMS website operation person in an enterprise, I know how important the custom field function of the content model is for building rich and personalized website content.It can not only help us organize information flexibly, but also provide users with more accurate filtering and display experience.I will explain in detail how to obtain the custom field parameters of the content model definition in Anqi CMS and perform effective filtering and display. ### Create and manage custom content model fields Firstly, all functions are based on the configuration in the background.In AnQi CMS

2025-11-06

How to display a list of recommended articles related to the current article on the article detail page?

As an experienced security CMS website operator, I fully understand the importance of high-quality content and refined operation for user retention and website SEO.Display related recommended articles on the article detail page, which can not only effectively extend the user's time on the site and reduce the bounce rate, but also optimize through internal links, improve the overall weight of the website, and is an indispensable part of content operation.Below, I will give a detailed introduction on how to implement this feature in Anqi CMS.

2025-11-06

How can you easily obtain and display the link and title of the previous and next articles on the article detail page?

As an experienced website operator familiar with AnQiCMS, I fully understand the importance of effectively guiding users to browse and discover more content in content management.The navigation of the previous/next article on the article detail page not only can significantly improve user experience and prolong the time users stay on the site, but also helps to optimize the internal link structure of the website, which is very beneficial for SEO.I will elaborate in detail on how to conveniently and quickly obtain and display the links and titles of the previous and next articles on the article detail page of AnQiCMS.--- ###

2025-11-06

How to retrieve and display the website's comment list, including multi-level replies?

As a website content expert who deeply understands the operation of Anqi CMS, I am well aware of the readers' needs for interactivity and information transparency.The comment feature is an important way for users to participate in website content construction and express their opinions, and multi-level replies can effectively promote in-depth communication between users.AnQi CMS provides us with a powerful and flexible comment management mechanism, making it efficient and convenient to retrieve and display comment lists, including multi-level replies.

2025-11-06

How to embed and display a user留言表单in a template?

As a website operator who deeply understands the operation of AnQiCMS, I fully understand the importance of providing user interaction channels on the website.The user feedback form is a key tool for collecting feedback, answering questions, and building relationships with users.In AnQiCMS, embedding and displaying a comment form through its flexible template engine is a direct and highly customizable process.This article will detail how to implement this feature in the AnQiCMS template.

2025-11-06

How to retrieve and display the list of友情链接 configured in the background?

As an experienced CMS website operation personnel, I fully understand the importance of efficient content management and front-end display for the success of the website.Friend links are an important part of a website's external cooperation and SEO optimization, and their convenient acquisition and display methods are an indispensable part of daily operation.Now, I will elaborate on how to obtain and display the list of友情链接 links configured in the AnQiCMS admin panel.### AnQi CMS: Efficient management and display of the background friendship link list Friendship links, as an important part of website external link construction

2025-11-06

How to implement and display pagination navigation on list pages (such as article lists, search results)?

As an experienced CMS website operations personnel for an Internet security company, I know that the details of content presentation are crucial for user experience and website SEO.Page navigation is one of the fundamental and key components, which not only helps users efficiently browse a large amount of content, but also allows search engines to better crawl and index website information.Today, I will elaborate on how to elegantly display pagination navigation on the list page of AnQi CMS, such as article lists, search result pages, etc.### Overview of Pagination Mechanism in AnQi CMS Implementing pagination functionality in AnQi CMS is intuitive and efficient

2025-11-06