If you want to get the details of a Tag label (such as name, link, description), which template tag should you use?
As an experienced website operation expert, I am well aware 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 content organization forms like Tag tags, which are important, it is crucial to accurately obtain and display their detailed information, which is vital for SEO optimization and user experience.
Today, let's delve into a question that many people often encounter: 'If you want to get the detailed information (such as name, link, description) of a certain Tag label, which template tag should you use in Anqi CMS?'
Unveil the details of the Anqi CMS tag:tagDetailThe tag is your favorite
In the AnQi CMS template system, when you need to focus on a specific Tag label and extract its unique attributes, the system provides a template tag specifically designed for this purpose -tagDetail. It acts as a data scout, able to delve into the tag library, searching and returning all the detailed information you need.
tagDetailThe core function of tags is to obtainIndividual Tag tagThe complete data object or its specific fields. 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 details page, the related tags area on an article details page, or the sidebar recommendation area).
How to usetagDetailTag information acquisition?
tagDetailThe use of tags is very intuitive, and it usually works with some parameters to accurately specify which information of which Tag you want to get.
Specify Tag label method:
- Automatically obtained on the current page:When you are on the detail page of a Tag label,
tagDetailTags do not require any additional parameters to automatically identify and retrieve the Tag information of the current page. This is the most common usage and the most convenient way. - Specify through ID:If you know the unique ID of the Tag label (visible in the background management), you can specify it through
idparameters. For example,id="1"it will retrieve 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), and you can also usetokenthe parameter to specify. For example,token="seo-optimization"Get the Tag label with the alias “seo-optimization”.
- Automatically obtained on the current page:When you are on the detail page of a Tag label,
The specific field to be retrieved:
tagDetailTag throughnameParameters allow you to precisely select the Tag information to display. The following are some common fields and their meanings:Id: The unique identifier (ID) of the Tag tag.Title: Tag label display name, this is the most intuitive information the user sees.Link: The URL address corresponding to the Tag label, clicking on it will usually jump to the article list page under the Tag.Description: A brief description of the Tag label, which is very helpful for SEO and users to understand the meaning of the label.FirstLetter: The initial letter of the Tag label name, often used in alphabetical sorting of tag clouds.LogoIf the label is configured with a Logo image, the URL can be obtained through this field.ContentThe detailed content or description of the label (if filled in on the back-end).
An example of practical application: retrieve and display the name, link, and description of a Tag
Assuming you are building an article detail page, you want to list all the tags belonging to the article at the bottom of the page, and clicking on these tags can jump to their detail pages.Or do you want to display detailed information about a popular Tag in a sidebar.
The following is a simple code snippet that demonstrates how to retrieve 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 of obtaining: directly outputting a field, assigning a field to a variable and then using it, and obtaining the entire Tag object and accessing its properties through dot notation. Among them,featuredTag.Link/featuredTag.TitleandfeaturedTag.DescriptionIt is through the obtained Tag object that you can access its specific information.
Broaden your horizons:tagListwithtagDataList
AlthoughtagDetailFocus 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 a website, or the related tags of a particular article/product, you should use
tagListLabel. It can return an array of Tag objects for you to loop through and display 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 a list of all related articles, products, and other documents under the Tag on the detail page or topic page, then
tagDataListThe label is 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 %}
Understand the respective responsibilities of these tags, which will help you build the Tag feature of the website more efficiently and accurately.
**Tips for Practice**
- Refer to the documentation:Although this article provides a detailed explanation, the official documentation of Anqi CMS is always your most reliable reference. When in doubt, please refer to it first.
design-tag.md/tag-/anqiapi-tag/148.html/tag-archiveTag.mdandtag-/anqiapi-tag/149.htmland related documents. - Maintain consistency:When displaying Tag information on the website, try to maintain consistency in style and logic, which helps users better understand and navigate.
- SEO friendly:The tag name, description, and link are important SEO elements. Ensure they are clear, accurate, and contain relevant keywords.
By cleverly usingtagDetailTags and their 'sibling' tags, you can make the Tag function of Anqi CMS website work to its maximum effect, whether it is to improve the discoverability of content, optimize search engine rankings, or improve the user's browsing experience, it will be twice as effective with half the effort.
Frequently Asked Questions (FAQ)
- Ask: I want to display a 'Hot Tags' list in the footer of the website, should I use
tagDetailOrtagList?**Ans