In AnQiCMS, effectively utilizing the tag function is a key factor in improving the organization of website content, optimizing user experience, and enhancing search engine visibility.Tags can not only help users quickly find the content they are interested in, but also provide website administrators with flexible content classification and association methods, breaking through the hierarchical restrictions of traditional classification.
AnQiCMS's tag feature is powerful and flexible, it allows content creators to add descriptive keywords or phrases to articles and products.These tags can be conveniently created, edited, and managed in the background management, and can be easily selected or added when articles are published.Once the content is tagged, we can use the built-in template tags of AnQiCMS on the front page to accurately display these tags and their associated content.
Display the tags of the current article on the article detail page
When visitors browse a specific article, they usually want to see tags related to the content of the article for further exploration of the same topic. In AnQiCMS, you can usetagListLabel this easily.
This label is usually used on article detail pages (such asarchive/detail.html
For example, to display all related tags below the article content, you can write the template code like this:
{# 假设这是文章详情页模板的一部分 #}
<div class="article-tags">
<strong>标签:</strong>
{% tagList tags %} {# 默认获取当前文档的标签 #}
{% for item in tags %}
<a href="{{item.Link}}" title="{{item.Title}}">{{item.Title}}</a>
{% endfor %}
{% endtagList %}
</div>
This code will traverse all the tags associated with the current article and generate a clickable link for each tag, linking to the detail page of the tag, making it convenient for users to click and view more related articles.
Create an independent label list page
To enable users to discover all tags on the website, you may need to create a separate tag list page, like a 'tag cloud' or 'tag index'. In AnQiCMS, template files are usually namedtag/index.htmlThis page is used to carry such pages.
On this page, we also usetagListtags, but this time no specificitemIdParameters, so it will retrieve all tags of the entire website. You can set it according to your needs.limitParameters to control the number of tags displayed.
For example, create a page that displays all tags:
{# tag/index.html 模板文件内容示例 #}
<h1>所有标签</h1>
<div class="tag-cloud">
{% tagList tags with limit="100" %} {# 获取网站前100个标签 #}
{% for item in tags %}
<a href="{{item.Link}}" title="{{item.Title}}">{{item.Title}} ({{item.ArchiveCount}}){# 假设你想显示每个标签的文章数量 #}</a>
{% endfor %}
{% endtagList %}
</div>
Hereitem.ArchiveCountAlthough it istag-archiveTag.mdofitemThe field is not directly listed, but in actual use, many CMS tag objects will contain the number of associated contents. If it is not supported in actuality, it can be ignored.Here is an example of how to expand the display information.
Through such a page, users can clearly see all the topics covered by the website and click to enter the detailed page of a specific tag.
Create tag detail pages and display related articles
When a user clicks on a specific tag (whether from the article detail page or the tag list page), they expect to see the detailed information of the tag as well as all articles associated with the tag. In AnQiCMS, such pages are usually handled bytag/list.htmlThe template file is responsible for rendering.
On this page, we will use two core tags:
tagDetailtagsEnglish for auto is EnglishtagDataListtags:Used to retrieve all articles associated with the current tag. It automatically identifies the current tag page.tagId,type="page"andpaginationand can be used with the tag to achieve pagination display of associated articles.
The following is an example of a template code for a label detail page.
English
<h1>标签:{{currentTag.Title}}</h1>
{% if currentTag.Description %}
<p>描述:{{currentTag.Description}}</p>
{% endif %}
{% endtagDetail %}