How to get and display the list of all documents associated with a specified Tag?

Calendar 👁️ 68

Manage content in AnQi CMS, in addition to organizing through categories, flexibly using the "Tag" feature is also a key to improving the aggregation ability of website content and user experience.Tags can connect documents of different categories and models but related to the same theme, providing visitors with more opportunities to discover content.How specifically can we obtain and display the list of all documents associated with the specified tags?Next, we will delve into this practical skill.

Understanding the Tag system of Anqi CMS

The tag design of Anqi CMS is very flexible, it does not depend on specific categories or models, and can cross content types to associate documents with similar themes.For example, an article about 'SEO optimization' and a product introduction about 'SEO tools', although belonging to different content models, can both be tagged with 'SEO', making it convenient for users to view all related content through the 'SEO' tag.

In the AnQi CMS template system, there are several tags closely related to tags, which together form the foundation for the display of tag content:

  • tagListTags:Used to obtain the tag list in the website, for example, displaying popular tags or relevant tags of the current document.
  • tagDetailTags:Used to obtain detailed information about a specific tag, such as tag name, description, etc., very suitable for use on tag detail pages.
  • tagDataListTags:This is the main character of today, it is specifically used to obtain the document list associated with a specified tag.

By combining these tags, we can easily achieve the need for aggregating various tag content displays.

Core: How to obtain the document list associated with a specified Tag

The most direct and effective way to obtain all documents associated with a specified tag is to usetagDataListLabel. This label is designed to be very intuitive, just tell it which label you are interested in, and it will list all related documents for you.

tagDataListBasic usage of tags

{% tagDataList archives with tagId="1" type="page" limit="10" %}
    {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <p>{{item.Description}}</p>
                <div>
                    <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                    <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>浏览量:{{item.Views}}</span>
                </div>
            </a>
            {% if item.Thumb %}
            <a href="{{item.Link}}">
                <img alt="{{item.Title}}" src="{{item.Thumb}}">
            </a>
            {% endif %}
        </li>
    {% empty %}
        <li>当前标签下还没有任何文档。</li>
    {% endfor %}
{% endtagDataList %}

In the above code snippet:

  • tagDataList archivesWe have defined a variablearchivesTo store the list of documents obtained.
  • tagId="1"This is the most critical parameter, it specifies which tag under which we want to retrieve the documents. You need to replace"1"with the actual ID of the target tag.
  • type="page"This parameter indicates that we want to display the document list in a paginated form, so that subsequent operations can combinepaginationThe tag implements pagination navigation. If you do not need pagination and just want to get a fixed number of lists, you can usetype="list".
  • limit="10": Specify 10 documents per page.
  • {% for item in archives %}: PassforLoop througharchivesEach document in the variable. Inside the loop,itemThe variable represents the current document object you are processing, you can accessitem.Title/item.Link/item.Descriptionto access the various properties of the document.
  • {{stampToDate(item.CreatedTime, "2006-01-02")}}: The document'sCreatedTimeIt is a timestamp, we need to usestampToDatea filter to format it into a readable date format.
  • {% empty %}: This is a very practical structure, whenarchivesWhen the list is empty (i.e., no related documents are found), it will display{% empty %}Content within the block, avoid blank pages.

Practice: Display document list in Tag detail page

In Anqi CMS, it is common to create a dedicated page for a tag to display all documents under that tag, such as/template/default/tag/list.htmlOr a custom label template). On this page, it is more convenient to get the list of documents associated with the current label, becausetagDataListThe label automatically recognizes the label ID of the current page.

Here is a complete example of how to display tag information and its associated document list on a tag detail page (assuming the page URL containstagIdortoken)

`twig {% extends ‘base.html’ %} {# Inherit the base template to ensure the page structure is complete #}

{% block title %}

<title>{% tdk with name="Title" siteName=true %} - 安企CMS</title>

{% endblock %}

{% block content %}

<div class="tag-header">
    <h1>标签:{% tagDetail with name="Title" %}</h1>
    <p class="tag-description">{% tagDetail with name="Description" %}</p>
    <span class="tag-letter">首字母:{% tagDetail with name="FirstLetter" %}</span>
</div>

<div class="tag-documents">
    <h2>“{% tagDetail with name="Title" %}”相关文档</h2>
    <ul>
        {% tagDataList archives with type="page" limit="10" order="id desc" %} {# 默认获取当前标签文档,并按ID倒序 #}
            {% for item in archives %}
            <li>
                <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
                {% if item.Thumb %}
                    <img src="{{item.Thumb}}" alt="{{item.Title}}" style="float: left; margin-right: 15px; width: 120px; height: 90px; object-fit: cover;">
                {% endif %}
                <p>{{item.Description}}</p>
                <div class="doc-meta">
                    <span>分类:<a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></span>
                    <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>浏览量:{{item.Views}}</span>
                </div>
                <div style="clear: both;"></div>
            </li>
            {% empty %}
            <li>非常抱歉,当前标签下暂时没有找到任何文档。</li>
            {% endfor %}
        {% endtagDataList %}
    </ul>

    {# 分页导航 #}
    <div class="pagination-wrapper">
        {% pagination pages with show="5" %}
            <ul>
                {% if pages.FirstPage %}
                    <li {% if pages.FirstPage.IsCurrent %}class="active"{% endif %}><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
                {% endif %}
                {% if pages.PrevPage %}
                    <li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
                {% endif %}
                {% for p in pages.Pages %}
                    <li {% if p.IsCurrent %}class="active"{% endif %}><a href="{{p.Link}}">{{p.Name}}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
                {% endif %}
                {% if pages.LastPage %}
                    <li {% if pages.LastPage.IsCurrent %}class="active"{% endif %}><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
                {% endif %}
            </ul>
        {%

Related articles

How to get and display the custom parameters of a specified document (such as author, source)?

When using AnQi CMS to manage your website content, you may find that relying solely on default fields such as title, content, and summary is not enough to fully meet the needs of personalized display.For example, you may wish to display 'author' and 'source' information on the article detail page, or show 'material' and 'size' and other specific parameters on the product page.The AnQi CMS provides powerful custom parameter features, allowing you to easily add, manage, and display these personalized information for different types of documents (such as articles, products).This article will provide a detailed introduction on how to obtain and display custom parameters of specified documents in AnQi CMS

2025-11-08

How to display related documents or search results on the article list page?

In website operation, how to make visitors find the content they are interested in faster, or seamlessly discover more related information after browsing an article, is the key to improving user experience and website stickiness.AnQiCMS (AnQiCMS) provides powerful and flexible template tags that can help us easily implement displaying related documents or search results on the article list page, thus building a more intelligent and interactive website.### Smartly using content list tags to present dynamic information One of the core advantages of AnQi CMS lies in its highly customizable template system

2025-11-08

How to implement pagination for article lists and limit the number of items per page?

In website operation, especially when managing a large amount of content, the pagination display of the article list is an indispensable function.It not only makes it easier for users to browse content, avoids the problem of too much data loading on a single page leading to slow speed, but also improves the overall user experience and SEO friendliness of the website.In AnQi CMS, it is very intuitive to implement pagination for the article list and flexibly control the number of items per page. Next, we will explore how to implement pagination for the article list in the Anqi CMS template and limit the number of articles displayed per page.--- ### Efficient Content Management

2025-11-08

How to filter tags through document parameters to achieve a combination display of list content with multiple conditions?

In content operation, we often need to display lists of content with different themes and properties, and allow visitors to filter according to their own needs. For example, a real estate website may need to filter listings by "house type", "location", "area range", and other multi-dimensional combinations.If each time is organized manually or developed custom, it is not only inefficient but also difficult to maintain.AnQiCMS (AnQiCMS) provides a flexible and powerful document parameter filtering mechanism that can help us easily achieve this combination display of list content with multiple conditions. Next

2025-11-08

How to retrieve and display the list of friend links of a website?

In website operation, friendship links play an important role in connecting each other, promoting traffic, and improving search engine rankings.A well-maintained, clear display of the friendship link area, which not only reflects the openness of the website, but also provides users with more valuable jump paths.AnQiCMS provides users with a convenient friend link management feature, allowing you to easily obtain and display these links on your website. ### Manage your friend links: Backend settings Before starting the front-end display, we need to make sure that the friend links have already been configured in the Anqi CMS backend. Usually

2025-11-08

How to add and display a captcha in the comment or message form to prevent spam?

When operating a website, spam comments and malicious messages are always a headache, as they not only affect user experience but may also damage the professional image of the website.Fortunately, AnQi CMS provides a simple and effective way to solve this problem - that is to add a captcha to the comment or message form.This can greatly enhance the security of the website, filtering out most automated spam information.Below, let's take a detailed look at how to add a captcha to your comment and message form in Anqi CMS.This process can be divided into two steps, which is very intuitive and easy to operate.### Step 1

2025-11-08

How to retrieve and display details of a specific category, including description, content, and Banner image?

When operating a website, we often need to display unique content for different category pages, such as a product category may have a detailed introduction and an eye-catching Banner image, while a news category may focus more on a concise description.AnQi CMS provides a flexible mechanism that allows us to easily retrieve and display detailed information about specific categories, including descriptions, content, and Banner images.### Backend settings are fundamental: enriching categories Before displaying category details on the frontend, we need to fill in this information in the Anqi CMS backend

2025-11-08

How to implement nested category display with multiple levels and how to judge if there is a subcategory in the template?

When building a website, a clear and organized content structure is crucial for enhancing user experience and SEO performance.AnQiCMS (AnQiCMS) relies on its flexible content model and powerful template engine, allowing us to easily implement complex multi-level nested display and subcategory judgment, thus creating highly customized navigation and content layouts. ### Backend Settings: Build Category Hierarchy In the Anqi CMS backend, the category management feature (usually located under the "Content Management" menu, below "Document Category") is the foundation for implementing multi-level categorization. First

2025-11-08