How to get the list of related documents associated with a TagID in AnQiCMS?

Unlock Content Association: How to Efficiently Retrieve Related Document Lists Based on TagID in AnQiCMS

In a content management system, tags (Tag) are an important tool for connecting content, enhancing user experience, and optimizing search engine visibility.AnQiCMS, as an enterprise-level content management system developed based on the Go language, deeply understands this field, and provides flexible and powerful tag features.For website operators, how to accurately obtain and display a list of associated documents based on a specific tag ID is a key aspect of refined content operation.Today, let's delve deeply into this practical feature in AnQiCMS, allowing you to easily navigate the associations between content, providing users with richer exploration paths.

The Unique Value of Tags (Tag) in AnQiCMS

In the design philosophy of AnQiCMS, tags are not just a simple categorization of content, they are more like bridges that organically link documents under different categories and even different content models (such as articles, products).Tags have high flexibility and aggregation, unlike the hierarchy and exclusivity of categories.A document can belong to a category but can be tagged with multiple tags, enabling it to be discovered from multiple dimensions.For example, an article about 'AnQiCMS Deployment Tutorial' might be tagged with 'AnQiCMS', 'Deployment', 'Go Language', 'Server Operation and Maintenance', and other tags, greatly expanding the reach of the content.

The AnQiCMS tag management feature allows you to easily view, add, edit, and delete document tags. Each tag has fields such as name, index letter, custom URL, and description, and even allows you to set independent SEO titles and keywords for tags. This is crucial for building clear website themes and improving the ranking of specific keywords.

On the template level, AnQiCMS provides dedicated tags for labels, such astagListUsed to obtain the tag list of all or specified documents on the website,tagDetailUsed to obtain detailed information of a specific tag. And today we focus on the.tagDataListtag is the core tool for obtaining the associated document list according to TagID.

Core: UtilizetagDataListGet document list by label

When we need to get all documents associated with a known label IDtagDataListTags are our preferred choice. It can accurately filter out all documents tagged with the provided TagID from the content library.

Let us understand its usage through a specific scenario. Assume you have a TagID of123The label, the name may be called "Go Language Development", now you want to display all articles related to "Go Language Development" on a certain page.

The basic calling method is very intuitive:

{% tagDataList archives with tagId="123" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
            <div>
                <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </div>
            {% if item.Thumb %}
            <img src="{{item.Thumb}}" alt="{{item.Title}}">
            {% endif %}
        </a>
    </li>
    {% empty %}
    <li>
        该标签下暂无相关文档。
    </li>
    {% endfor %}
{% endtagDataList %}

In this code,tagId="123"Explicitly inform AnQiCMS that we wish to retrieve all documents associated with the label having ID 123.archivesis our custom variable name, which will carry the list of obtained documents. Next, we iterate over this list and can access{% for item in archives %}the list, and can accessitem.Title/item.Link/item.Description/item.CreatedTime/item.Views/item.Thumbsuch document fields to build the display content.{% empty %}A block is a very considerate design, whenarchivesThe list is empty, it elegantly displays a prompt message to avoid the page from appearing blank or with errors.

It is worth mentioning that if you are currently on a tag detail page (such astag/list.htmlortag/detail.htmlSuch a template file), AnQiCMS will intelligently automatically identify the TagID of the current page. In this case, you can even omittagIdParameter, making the code more concise:

{% tagDataList archives %} {# 在标签详情页,会自动读取当前页面的 TagID #}
    {% for item in archives %}
    <li>
        {# 展示文档信息 #}
        <a href="{{item.Link}}">{{item.Title}}</a>
        <p>{{item.Description}}</p>
    </li>
    {% empty %}
    <li>
        当前标签下暂无相关文档。
    </li>
    {% endfor %}
{% endtagDataList %}

Advanced usage: Combine with other parameters for filtering and sorting

tagDataListThe power of tags is not limited to retrieving documents based on TagID, it also supports a series of parameters to help you finely control the retrieval and display of documents:

  • moduleId【en】Limit the content modelIf you only want to retrieve associated documents under specific content models (such as “Article Model” or “Product Model”), you can usemoduleIdparameters. For example,moduleId="1"usually represents an article model. “`twig {% tagDataList articles with tagId=“123” moduleId=“1” %} {# Only display the documents of the article model #} {% endtagDataList