As an experienced website operation expert, I know that flexibly using template tags in a high-efficiency content management system like AnQiCMS is the key to improving the efficiency of website content display and management.Especially for important content organization forms like Tag tags, it is crucial to accurately obtain and display their detailed information, which is essential for SEO optimization and user experience.
Today, let's delve into a common issue that many people encounter: 'Which template tag should be used in Anqi CMS to get detailed information about a Tag label (such as name, link, description)?
Reveal the details of the security CMS tag:tagDetailTags are your first choice
In the template system of AnQi CMS, when you need to focus on a specific Tag label and extract its unique properties, the system provides a template tag specifically designed for this purpose.tagDetailIt acts like a data scout, able to delve into the tag library and retrieve and return all the detailed information you need.
tagDetailThe core function of tags is to obtainIndividual Tag tagA complete data object or its specific field.This means you can easily display a Tag's name, its corresponding link, and its description at any location on the website (such as the tag detail page, the related tags area on the article detail page, or the sidebar recommendation area).
How to usetagDetailLabel gets Tag information?
tagDetailThe label is very intuitive and usually works with some parameters to accurately specify which Tag's information you want to get.
Specify Tag label in the following way:
- Automatically obtained on the current page:When you are on the detail page of a Tag label,
tagDetailTags do not require any additional parameters and will automatically identify and retrieve the Tag information of the current page. This is the most common usage and also the most convenient method. - Specify by ID:If you know the unique ID of the Tag label (visible in the background management), you can specify it explicitly through
idthe parameter. For example,id="1"you will get the Tag label with ID 1. - Specify through URL alias (Token):Tag labels usually have a readable URL alias (configured in the background, for example
seo-optimization) You can also usetokenThe parameter to specify. For example,token="seo-optimization"Will obtain the Tag tag with the URL alias “seo-optimization”.
- Automatically obtained on the current page:When you are on the detail page of a Tag label,
The specific fields obtained:
tagDetailTagged throughnameThe parameter allows you to accurately select the Tag information you need to display. The following are some commonly used fields and their meanings:Id: The unique identifier (ID) of the Tag tag.TitleTag label display name, this is the most intuitive information that users see.LinkEnglish: Tag label corresponding URL address, clicking on it will usually jump to the article list page under the Tag.Description:Tag label brief description, very helpful for SEO and users to understand the meaning of the label.FirstLetter:The first letter of the Tag label name, often used for alphabetical sorting of tag clouds.Logo:If the tag has a configured Logo image, you can obtain its URL through this field.Content:The detailed content or description of the tag (if filled in on the back end).
Actual application example: Get and display the name, link, and description of a Tag
Assuming you are building an article detail page, and you want to list all the Tags belonging to the article at the bottom of the article, and clicking on these Tags can jump to their detail pages.or would you like to display detailed information of a popular Tag in a sidebar.
The following is a simple code snippet demonstrating how to get the name, link, and description of a Tag:
{# 假设您正在Tag详情页,或者通过其他方式获得了当前Tag的上下文 #}
{# 示例1:获取当前Tag的标题并直接输出 #}
<div>当前Tag标题:{% tagDetail with name="Title" %}</div>
{# 示例2:获取指定ID的Tag链接 #}
<div>ID为10的Tag链接:<a href="{% tagDetail with name="Link" id="10" %}">点击查看</a></div>
{# 示例3:将Tag描述赋值给变量,然后输出 #}
{% tagDetail tagDescription with name="Description" %}
<p>标签描述:{{tagDescription}}</p>
{# 示例4:综合展示一个Tag的名称、链接和描述(通常在循环中或特定Tag展示区使用) #}
{% tagDetail featuredTag with id="5" %} {# 获取ID为5的特色Tag #}
{% if featuredTag %} {# 确保Tag存在才显示 #}
<div class="featured-tag">
<h3><a href="{{ featuredTag.Link }}">{{ featuredTag.Title }}</a></h3>
<p>{{ featuredTag.Description }}</p>
{% if featuredTag.Logo %}
<img src="{{ featuredTag.Logo }}" alt="{{ featuredTag.Title }}" />
{% endif %}
</div>
{% else %}
<p>特色标签未找到。</p>
{% endif %}
In the above example, we demonstrated three ways to obtain information: directly outputting a field, assigning a field to a variable and using it, as well as obtaining the entire Tag object and accessing its properties through dot notation. Among them,featuredTag.Link/featuredTag.TitleandfeaturedTag.DescriptionThis is through the obtained Tag object to access its specific information.
Broaden your horizons:tagListWithtagDataList
AlthoughtagDetailFocused on the details of a single Tag, but in actual operation, you may also encounter the following needs:
Get the Tag list of all Tags or documents:When you want to display a list of all Tags on the website, or the related Tags of a specific article/product, you should use
tagListLabel. It can return an array of Tag objects, which you can loop through to display the Tag names and links.{# 获取与当前文档相关的Top 10 Tag列表 #} {% tagList tags with itemId=archive.Id limit="10" %} {% for item in tags %} <a href="{{item.Link}}">{{item.Title}}</a> {% endfor %} {% endtagList %}Get all documents under a certain Tag:If you want to display the list of all related articles, products, and other documents under the Tag on the detail page or special page of Tag,
tagDataListLabels are your best choice. It will return an array of document (archive) objects.{# 在Tag详情页,获取当前Tag下的Top 10 文档列表 #} {% tagDataList archives with type="page" limit="10" %} {% for item in archives %} <a href="{{item.Link}}">{{item.Title}}</a> {% endfor %} {% endtagDataList %}
Understanding the respective roles of these tags will help you build the website's Tag function more efficiently and accurately.
**Practical Tips**
- Check the documentation:Even though this article provides a detailed explanation, the official documentation of AnQi CMS is always your most reliable reference. When in doubt, please refer to the relevant documents first.
design-tag.md/tag-/anqiapi-tag/148.html/tag-archiveTag.mdandtag-/anqiapi-tag/149.html等相关文件。 - Maintain consistency:Display Tag information on the website as consistently as possible in terms of style and logic, which helps users better understand and navigate.
- SEO-friendly:The name, description, and link of the tag are important SEO elements. Make sure they are clear, accurate, and contain relevant keywords.
By cleverly usingtagDetailLabel and its 'sibling' labels, you can make the Tag feature of Anqi CMS website work to the maximum effect, whether it is to improve the discoverability of content, optimize search engine rankings, or enhance the user's browsing experience, it will be twice as effective with half the effort.
Common Questions (FAQ)
- 问:I want to display a 'Hot Tags' list in the footer of the website, should I use
tagDetailOrtagList?**Answer