As an experienced website operations expert, I know that effectively utilizing tags (Tags) in a content management system is crucial for the SEO, content organization, and user experience of the website.AnQiCMS (AnQiCMS) with its powerful template features and flexible tag system allows you to easily display and manage this valuable information on the website front-end.Today, let's delve deeply into how to accurately obtain the name, link, and description of a specified Tag in AnQiCMS, thereby providing stronger support for your content operations.
In AnQiCMS, tags are not just an accessory attribute of articles, but also exist as an independent content entity in themselves, having their own names, links, and descriptions.This design allows the tabs to become valuable traffic entry points and improve user experience through personalized display.AnQiCMS template language is similar to Django, with a simple and intuitive syntax. Even operators without a deep programming background can quickly get started.
Master the core tags of Tag data
To get the name, link, and description of the Tag, we mainly use the two core template tags provided by AnQiCMS:tagDetailandtagListThese tags are used to retrieve detailed information for a single specific Tag and to iterate over multiple Tag lists.
1. Retrieve detailed information for a specified Tag (tagDetail)
When you need to retrieve the complete information of a specific Tag (for example, you know its ID or URL alias),tagDetailThe tag is your preference. It can help you accurately extract the name, link, description, even including the index letter or custom content of the Tag.
Usage scenario:
- On the Tag detail page, display the detailed introduction of the current Tag.
- On the article detail page, display the exclusive description of the Tag based on 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 obtained data to a variable so that it can be referenced multiple times 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 pass throughnamethe parameters to specify the specific fields you want to retrieve, such asTitle(Name),Link(Link),Description(Description) and others.id="TagID"ortoken="URL别名"You can use Tag'sIDor itsURL别名Specify the specific Tag to retrieve information. If you are 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 obtain Tag information under other sites, you can use this parameter. Generally, it is not necessary to fill in.
Available field name: Besides the name, link, and description,tagDetailother useful fields are provided, such as:
Id: The unique identifier ID of the Tag.Title: The name of the Tag.Link: The link address corresponding to the Tag.Description: The description content of the Tag.FirstLetter: The first letter of the Tag name (used for alphabetical sorting, etc.).Content: Custom content of the Tag (if set in the background).Logo: Thumbnail or Logo of the Tag (if set in the background).
Actual application example:
Assuming you have a Tag's ID is5Or 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|safeA filter to prevent 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>
By these methods, you can flexibly obtain and display detailed information about a specified Tag at any location on the website, whether it is used to beautify the page, improve the user experience, or strengthen the relevance of the content.
Second, traverse and obtain the basic information of multiple Tags (tagList)
In addition to getting 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 point,tagListthe tag comes into play.
Usage scenario:
- List all the Tags associated with the current article on the article detail page.
- Display a list of popular Tags on the homepage or sidebar.
- Build a Tag index page, listing all Tags by alphabet or category.
tagListthe basic usage of tags is{% tagList 变量名称 with limit="数量" %}And it needs to match withforLoop to iterate through each Tag.
变量名称: Usually named astagsOr another meaningful name, used toforiterate in the loop.limit="数量": Limit the number of returned Tags, for examplelimit="10"Display only 10 Tags. You can also useoffsetpattern, such aslimit="2,10"Start retrieving 10 records from the second one.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 try to get the Tag of the current document.To get all Tags, you can set it toitemId="0".letter="首字母": Filter by the first letter of the Tag name, for exampleletter="A"Only display Tags starting with A.categoryId="分类ID": Filter by the category ID of the Tag.siteId="站点ID": SametagDetailFor multi-site management.
tagListThe tag will return a Tag object.