As an experienced website operations expert, I am well aware that effectively utilizing tags (Tags) in content management systems is crucial for website SEO, content organization, and user experience.AnQiCMS (AnQiCMS) boasts powerful template functions and a flexible tag system, allowing you to easily display and manage these valuable pieces of information on the front end of your website.Today, let's delve into how to accurately obtain the name, link, and description of a specified Tag in AnQiCMS, thereby providing stronger support for your content operation.

In AnQiCMS, tags are not just an auxiliary attribute of articles; they also exist as an independent content entity, with their own names, links, and descriptions, among other information.This design allows the tabs to also become a valuable traffic entry point and enhance user experience through personalized display.The template language of AnQiCMS is similar to Django, with simple and intuitive syntax, even operators without a strong programming background can quickly get started.

Master the core tags of Tag data

To get the name, link, and description of Tag, we will mainly use the two core template tags provided by AnQiCMS:tagDetailandtagListThese two tags are used to get the detailed information of a single specific Tag and to traverse multiple Tag lists.

1. Get the detailed information of a single specified Tag (tagDetail)

When you need to retrieve complete information for a specific Tag (for example, you know its ID or URL alias),tagDetailTags are your favorite. They can help you accurately extract the name, link, description, even including its index letter or custom content of the Tag.

Use Cases:

  • Display the detailed introduction of the current Tag on the Tag detail page.
  • On the article detail page, display the exclusive description of the Tag according to the main Tag of the article.
  • Display information of a fixed Tag at a specific location, such as a specific recommendation Tag in the 'Hot Tags' area.

tagDetailThe basic usage of tags is{% tagDetail 变量名称 with name="字段名称" id="TagID" %}. Among them:

  • 变量名称You can choose to assign the data obtained to a variable for multiple references in the template. If you do not specify a variable name, the data will be output directly.
  • name="字段名称"This is the most critical part, you need to specify through the parametersnamethe specific fields you want to retrieve, such asTitle(Name),Link(Link),Description(Description) etc.
  • id="TagID"ortoken="URL别名"You can use Tag'sIDor itsURL别名Specify the specific Tag to retrieve information. If it is on the Tag detail page, it is usually not necessary to specify, as the system will automatically identify the Tag of the current page.
  • siteId="站点ID"In multi-site management, if you need to retrieve Tag information from other sites, you can use this parameter. Generally, it is not required to fill in.

Available field namesOther than the name, link, and description,tagDetailother useful fields are also provided, such as:

  • Id: The unique identifier ID of the Tag.
  • Title: The name of the Tag.
  • Link[en] : Tag's corresponding link address.
  • Description[en] : Description content of Tag.
  • FirstLetter[en] : The initial letter of Tag name (used for alphabetical sorting, etc.).
  • ContentThe custom content of the Tag (if any is set in the backend).
  • LogoThe thumbnail or Logo of the Tag (if any is set in the backend).

Actual application example:

Assuming you have a Tag with an ID of5or its URL alias isanqicms-tips.

Get the name of the specified Tag:

{# 直接输出 Tag ID 为 5 的名称 #}
<div>指定 Tag 名称:{% tagDetail with name="Title" id="5" %}</div>

{# 将 Tag ID 为 5 的名称赋值给变量 'myTagName' 并输出 #}
{% tagDetail myTagName with name="Title" id="5" %}
<p>我的专属标签名称是:{{ myTagName }}</p>

{# 如果是当前 Tag 详情页,通常可省略 ID,例如 URL 别名为 anqicms-tips 的页面 #}
<p>当前页面标签名称:{% tagDetail with name="Title" %}</p>

Get the link of the specified Tag:

{# 直接输出 URL 别名为 'anqicms-tips' 的 Tag 链接 #}
<p>相关主题链接:<a href="{% tagDetail with name="Link" token="anqicms-tips" %}">点击查看更多安企CMS技巧</a></p>

{# 将 Tag 链接赋值给变量 'myTagLink' 并输出 #}
{% tagDetail myTagLink with name="Link" token="anqicms-tips" %}
<p>访问 {{ myTagLink }} 获取更多信息。</p>

Get the description of the specified Tag: The description of the Tag may contain rich text or HTML, therefore it is recommended to use|safeFilter to avoid content from being escaped, thus rendering HTML structure correctly.

{# 直接输出 Tag ID 为 5 的描述 #}
<div class="tag-description">
    {% tagDetail with name="Description" id="5" %}|safe %}
</div>

{# 将 Tag 描述赋值给变量 'myTagDescription' 并输出 #}
{% tagDetail myTagDescription with name="Description" id="5" %}
<div class="tag-intro">{{ myTagDescription|safe }}</div>

You can flexibly retrieve and display detailed information of the specified Tag at any location on the website, whether it is for beautifying the page, enhancing user experience, or strengthening the relevance of content.

Second, traverse and retrieve basic information of multiple Tags (tagList)

In addition to obtaining the details of a single Tag, you may also need to display multiple Tags, such as showing related Tags at the bottom of an article, creating a Tag Cloud, or displaying popular Tags in the sidebar. At this time, tagListTags come into play.

Use Cases:

  • List all tags associated with the current article on the article detail page.
  • Display the list of popular tags on the homepage or sidebar.
  • Build a Tag index page, listing all Tags alphabetically or by category.

tagListThe basic usage of tags is{% tagList 变量名称 with limit="数量" %}and should be paired withfora loop to iterate through each Tag.

  • 变量名称which is usually namedtagsOr another meaningful name, used inforiterating through the loop.
  • limit="数量": Limits the number of returned Tags, for examplelimit="10"to display only 10 Tags. You can also use theoffsetpattern, such aslimit="2,10"Start from the 2nd item and get 10 items.
  • itemId="文档ID"If you want to get the Tag associated with a specific document (article or product), you can use this parameter.If not specified, and the current page is the document detail page, it will attempt to retrieve the current document's Tag.itemId="0".
  • letter="首字母": Filter by the first letter of the Tag name, for exampleletter="A"Only show Tags starting with A.
  • categoryId="分类ID":Filter by the category ID of the Tag.
  • siteId="站点ID":Same.tagDetail,Used for multi-site management.

tagListTag will return a Tag object.