How to implement the `{% tagList %}` tag to retrieve its associated tags by document ID?

Calendar 👁️ 52

AnQiCMS (AnQiCMS) is an efficient and flexible content management system, whose powerful template tag system is the key to achieving personalized display for content operators and website developers. Today, we will delve into one very practical tag:{% tagList %}It is especially important to skillfully use it to accurately obtain and display the associated tags based on the document ID. This is crucial for building a website with rich content and strong relevance.

Label and content association: Improve user experience and SEO

In content operations, it is a common practice to add 'Tags' to articles, products, and other documents.It can not only help users quickly find relevant content, but also provide clearer semantic information for search engines, thereby optimizing the internal link structure and SEO performance of the website.Aqie CMS is well-versed in this, providing a comprehensive tag management function, which is reflected in its powerful template tags.

Core function analysis:{% tagList %}withitemIdParameter

{% tagList %}The tag is the core tool of Anqi CMS used to list document tags.Its basic usage is to traverse the tags of a website. However, to achieve the specific requirement of 'retrieving associated tags by document ID', we must rely ontagLista key parameter of the tag:itemId.

UnderstandingitemIdpower

itemIdParameters are like an intelligent filter, it tells{% tagList %}Tags only return those tags associated with the specified document ID. Its usage is very flexible:

  1. Default behavior (current document): When you use directly in a document detail page (such as an article detail page){% tagList tags %}When labeling, if not explicitly specifieditemIdThe system will intelligently identify the document ID of the current page and automatically retrieve the associated tags. This is the most common and convenient usage.

  2. Explicitly specify the document IDIf you want to get the associated tags of any document on the website rather than the document of the current page, you can specify the document ID in the following form. For example,itemId="[文档ID]".itemId="10"Will retrieve all tags associated with the document with ID 10.

  3. Retrieve all tags (not based on document association): Although it is a bit off topic for today's theme, but understanditemId="0"The function is also very helpful. WhenitemIdis set to"0"then,tagListWill no longer be filtered according to any specific document, but will return all tags on the website. This is usually used to build a tag cloud or tag index page for the entire site.

The data structure is returned

When{% tagList %}After the tag is executed, it will store the list of matched tags in a variable (for example, we often name ittagsThis variable is an array object, where each element represents an independent tag and contains the following key attributes for display in the template:

  • Id: Unique ID of the label.
  • Title: The display name of the tag, such as “website operation”, “SEO optimization”.
  • Link: The URL link of the tag, clicking on it will usually jump to the document list page under the tag.
  • Description: Description information of the tag (if set in the background).
  • FirstLetter: The initial letter of the tag name (used for sorting by letters, etc.).
  • CategoryId: If the tag is associated with a specific category (although the document tags themselves are not categorized, certain special settings may exist for this field).

Practice: Retrieve associated tags by document ID

Now, let's look at how to apply it in different scenarios through specific code examplesitemIdParameter.

Scenario one: Get the associated tags of the current document

Suppose you are editing a template for an article detail page (for examplearchive/detail.html),You want to display all the tags associated with the current article at the bottom of this page. At this time, you can write the code like this:

<div class="article-tags">
    <h4>文章标签:</h4>
    {% tagList tags %} {# 在文档详情页,未指定itemId时会自动获取当前文档的标签 #}
        {% if tags %} {# 判断是否有标签存在 #}
            <ul>
            {% for item in tags %}
                <li><a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a></li>
            {% endfor %}
            </ul>
        {% else %}
            <p>该文章暂无关联标签。</p>
        {% endif %}
    {% endtagList %}
</div>

In this code block,{% tagList tags %}Not explicitly passeditemId,AnQi CMS will intelligently parse it to obtain the associated tags of the current document, thenforloop through and display the title and link of each tag.

Scenario two: Retrieve associated tags by specifying document ID

Sometimes, you may need to retrieve information on a non-document detail page, or you may want to retrieve information on a document detail pageotherA specific document's associated tags. For example, in a sidebar recommendation area, you want to display all the tags of a popular article (assuming ID 123).

First, you need to make sure to get the ID of the document. You can use{% archiveDetail %}tags to get the ID of the specified document, and then pass this ID to{% tagList %}.

<div class="featured-article-tags">
    <h4>热门文章“AnQiCMS功能解析”的标签:</h4>
    {# 先获取热门文章(ID为123)的ID #}
    {% archiveDetail featuredArticle with name="Id" id="123" %}
        {% set articleId = featuredArticle %} {# 将文档ID赋值给一个变量 #}
    {% endarchiveDetail %}

    {# 再使用这个变量ID来获取关联标签 #}
    {% tagList tags with itemId=articleId %}
        {% if tags %}
            <ul>
            {% for item in tags %}
                <li><a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a></li>
            {% endfor %}
            </ul>
        {% else %}
            <p>指定文章暂无关联标签。</p>
        {% endif %}
    {% endtagList %}
</div>

This example demonstrates how to perform chained operations, first byarchiveDetailretrieving the ID of a specified article, then assigning the ID toarticleIda variable, finallytagListTag throughitemId=articleIdThe parameter accurately retrieves all related tags of this popular article.

More application scenarios and considerations

ByitemIdparameter,{% tagList %}The flexibility of tags has been greatly enhanced. You can take advantage of this feature to achieve:

  • Enhance the page relevance of the articleShow related tags at the bottom of the article to guide users to more content of the same topic.
  • Build dynamic content blocksOn the homepage or category page, display tags for specific "recommended articles" or "latest products" to provide more click-through options.
  • Personalized recommendations: Combine user behavior analysis to dynamically load tags of articles that users may be interested in.
  • SEO optimizationThrough displaying related tags, increase the internal link density between pages, and enhance the weight distribution of keywords.

Summary

Of Security CMS{% tagList %}Label collaborationitemIdThe parameter provides powerful tools for website content operation. Whether it is intelligently identifying the current document or accurately specifying any document, it can help you efficiently obtain and display tags associated with the document.Master this skill and you will be able to better organize website content, improve user experience, and optimize the website's search engine performance.

Frequently Asked Questions (FAQ)

  1. Question:itemIdthe parameter to0What effects will there be?Answer: WhenitemIdthe parameter to0then,{% tagList %}The tags will no longer be filtered based on any specific document, but will return the list of all tags on the website.This is usually used to build a tag cloud or tag index page for the entire site, rather than the associated tags of a specific document.

  2. Ask: Can I call tags of articles from other categories on the article detail page?Answer: Absolutely.itemIdThe parameter only cares about the unique ID of the document, not the category it belongs to. So, you just need to know the specific ID of the document you want to retrieve the tag for (regardless of which category it belongs to), and then use it asitemIdthe value is passed to{% tagList %}Just do it.

  3. Question: If a document is not associated with any tags,{% tagList %}what will be displayed?Answer: If a document is not associated with any tags, then{% tagList %}The variable defined by the tag (for exampletags) will be an empty array. In the template, you can use{% if tags %}To determine if the tag list is empty, and display "No tags" or other prompts accordingly to optimize the user experience.

Related articles

Does the document tag support marking and management across content models (such as articles and products)?

In the ever-changing field of digital marketing, the efficient organization and management of website content is the foundation of success.As an expert who has been deeply involved in website operations for many years, I am well aware of the importance of a flexible and powerful content management system (CMS) for improving operational efficiency and user experience.AnQiCMS (AnQiCMS) has won a good reputation in the industry with its excellent performance and rich features.Today, we will delve deeply into a key issue often mentioned in content operation: Does Anqi CMS support tagging and management across content models?## SecureCMS: Label

2025-11-06

How to add, edit, and delete document tags in the AnQiCMS backend management interface?

As an experienced website operations expert, I fully understand that how to efficiently organize and manage content in a content management system is crucial for the healthy development of a website.AnQiCMS, with its powerful functions and flexible customization, has provided us with many conveniences, among which the management of document tags is an indispensable part of content operation.Labels can not only help users find related content quickly, but are also an important tool to improve website SEO performance and content aggregation capabilities. Today

2025-11-06

What are the specific benefits of custom URL settings for document tags in SEO?

As an experienced website operations expert, I know that every detail of optimization can bring significant traffic growth and brand enhancement to the website.In AnQiCMS (AnQiCMS), such a powerful and SEO-friendly content management system, fully utilizing its various features is the key to success.Today, let's delve deeply into a seemingly minor but actually profound feature: the specific benefits of custom URL settings for document tags in SEO.

2025-11-06

How to get all associated documents under a specific Tag using the `{% tagDataList %}` tag?

How to skillfully use the `{% tagDataList %}` tag to accurately aggregate content in AnQi CMS?In the world of content operation, tags (Tag) are the bridges connecting content with users.It not only helps us better organize and classify massive amounts of information, but also significantly improves the efficiency of content discovery and the SEO performance of websites.For users of AnQiCMS, fully utilizing its powerful tag function is a key step in achieving content precision operation. Today

2025-11-06

How to combine the `{% tagDataList %}` tag with the pagination feature (`{% pagination %}`)?

In the flexible and powerful AnQiCMS content management system, efficiently organizing and displaying content is the key to the success of website operation.For many websites, aggregating related articles by tags (Tag) and providing convenient pagination browsing features is a common need to improve user experience and website SEO performance.

2025-11-06

How to set independent SEO titles, keywords, and descriptions for document tags?

As an experienced website operations expert, I know that every page's SEO optimization is crucial for the overall performance of the website, even for seemingly insignificant document tab pages.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, providing powerful SEO configuration capabilities for all types of content.Today, let's delve deeply into how to set independent SEO titles, keywords, and descriptions for document tags in AnQi CMS, so that your tab can also stand out in search engines.

2025-11-06

What is the use of the 'index letter' function of document tags, and how to apply it in the front-end template?

As an experienced website operations expert, I am happy to delve into the mysteries of the 'Index Letter Function' of the Anqi CMS and its application in the front-end template.This seemingly simple feature actually contains great potential to improve user experience, optimize information architecture, and even help with SEO. --- ## The Index Letter Function of Tags: The 'Guiding Light' of Content Organization in AnQi CMS Tags (Tag) are an important tool for organizing content and establishing associations in content management systems.

2025-11-06

If the document tag has a content field (Content), how to use the `render=true` parameter to correctly display Markdown content?

As an experienced website operations expert, I am more than happy to explain in detail how to skillfully use the `render=true` parameter to correctly and beautifully display Markdown content when the document tag contains the content field (Content) in Anqi CMS.This is not only about technical implementation, but also the key to improving the presentation effect and reader experience.

2025-11-06