As an experienced website operation expert, I have accumulated rich experience in the practical application of content management systems, especially AnQiCMS (AnQiCMS).I know, efficient content operation cannot be separated from the in-depth exploration and flexible application of system functions.Today, we will focus on a powerful and commonly used tag in the AnQiCMS template——{% tagList %}Explore how to cleverly use it to obtain and display a specified number of document tag lists to optimize the layout of website content and user experience.
Tags, the "DNA" of website content.
In modern content operation, tags play a crucial role.They are like the 'DNA' of content, able to describe the core theme of an article or product from multiple dimensions, helping users quickly find content they are interested in, and also providing more semantic information for search engines, thus enhancing the SEO performance and quality of internal links on the website.A well-designed tag system that not only makes the website structure clearer but also effectively extends the user's stay on the site, guiding them to discover more related valuable content.
AnQiCMS provides an intuitive and powerful backend support for tag management, you can easily add, edit and manage tags for documents (for details, please refer tohelp-content-tag.md)。While presenting these meticulously managed tags on the website frontend, we need today's star character——{% tagList %}.
Use cleverly{% tagList %}:Retrieve a specified number of tag lists
{% tagList %}Is the core tag used to obtain the document tag list in the AnQiCMS template engine. Its basic syntax structure is concise and clear, usually ending with{% tagList 变量名 %}and ends with{% endtagList %}and passing throughforLoop through label data.
For example, the basic way to call the label list is:
{% tagList tags %}
{% for item in tags %}
<a href="{{item.Link}}">{{item.Title}}</a>
{% endfor %}
{% endtagList %}
This code will retrieve all available tags and display their names and links one by one.However, in actual operation, we often do not need to display all tags at once, but rather hope to selectively display a specified number of tags based on page layout, content strategy, or user needs. At this point,limitParameters are particularly important.
Precisely control the quantity:limitThe magic of parameters
limitThe parameter allows you to specify the exact number of tags you want to retrieve. For example, if you only want to display the latest 5 popular tags in the sidebar, you can use it like this:
{% tagList tags with limit="5" %}
<div class="sidebar-tags">
<h3>热门标签</h3>
<ul>
{% for item in tags %}
<li><a href="{{item.Link}}" title="查看所有关于{{item.Title}}的文档">{{item.Title}}</a></li>
{% endfor %}
</ul>
</div>
{% endtagList %}
By usinglimitis set to"5"The system will only return the first 5 tags. It should be noted that,limitThe parameter range is usually from 1 to 100, and you can adjust this number according to your actual needs.
Furthermore,limitThe parameter also supportsoffset(Offset) mode, this allows you to start retrieving a specified number of tags from a specified position in the tag list. For example, if you want to skip the first 2 tags and display the next 8 tags, you can set it up like this:
{% tagList tags with limit="2,8" %} {# 从第3个标签开始(跳过前2个),获取8个标签 #}
<div class="advanced-tags">
<h3>进阶标签展示</h3>
<p>(跳过前两个,展示接下来8个)</p>
<ul>
{% for item in tags %}
<li><a href="{{item.Link}}"># {{item.Title}}</a></li>
{% endfor %}
</ul>
</div>
{% endtagList %}
Here"2,8"Indicate skipping the first 2 tags in the list and then obtaining 8 tags starting from the 3rd tag. This flexibility is very useful when building complex tag clouds or multi-block tag displays.
More practical parameter expansion
exceptlimitparameter,{% tagList %}Also provides some other parameters to make the acquisition of tags more accurate and contextually relevant:
itemId: If you want to get the tags of a specific document, you can use them on the document detail pageitemId=archive.Id(Supposearchiveis the current document object). If set toitemId="0"This indicates that all tags on the site are being retrieved, not bound to the current document.{% archiveDetail currentArchive with name="Id" %} {# 假设这里已经获取了当前文档ID #} {% tagList tags with itemId=currentArchive limit="5" %} <h4>当前文档的相关标签:</h4> {% for item in tags %} <a href="{{item.Link}}">{{item.Title}}</a> {% endfor %} {% endtagList %}categoryId: When you want to display tags included in documents under a specific category, you can use this parameter. For example,categoryId="1,2"The tags associated with the document of category ID 1 or 2 will be retrieved.letter: Used to filter tags that start with a specific letter, for exampleletter="A"Only tags starting with the letter A will be displayed, which is very useful when building an A-Z tag index.siteId: For users who use the AnQiCMS multi-site management function,siteIdCan specify from which site to obtain tag data, to achieve cross-site content calling.
Content operation strategy and **practice
Mastered{% tagList %}Usage, next is how to maximize its value in operation:
- Sidebar / footer tag cloud:Utilize
limitDisplay the most popular or latest few tags on the website to attract user clicks and increase the weight of internal links. - Tags related to the article detail page:Combine
itemIdParameters, displayed at the bottom of each article to show tags closely related to the article, guiding users to read similar themed content in depth. - Special page tag classification:Use for specific categories or special themes,
categoryIdFilter parameters to display related tags, strengthen the aggregation of thematic content. - Avoid "tag stacking":Labels should be precise and relevant, not just a simple list of keywords. Too many irrelevant labels can dilute the weight of keywords, affecting user experience and SEO performance.
- Regular maintenance:The operation staff should regularly check and clean up unused, duplicated, or outdated tags to ensure the vitality and effectiveness of the tag system.
Summary
{% tagList %}The tag is an indispensable tool in the AnQiCMS content operation toolset. By flexibly using itlimit/itemIdParameters such as these allow you to precisely control the number and range of tags displayed on the website's front end, which not only optimizes the visual layout of the page but also effectively improves the efficiency of users in discovering content and the overall SEO performance of the website.Hope this article can help you better understand and apply this feature, making your website content more attractive!
Frequently Asked Questions (FAQ)
Q1:limitWhat is the range of parameter values? What should I do if I want to display all tags?
A1: limitThe parameter range is usually from 1 to 100. If you want to display all tags, you can omitlimita parameter, or set a sufficiently large number (such aslimit="100"), but AnQiCMS usually defaults to fetching all, unless a specific pagination type is specified.
Q2: How to make{% tagList %}Display only the tags of the current document, not the tags of the entire site?
A2:In the document detail page, you can useitemId=archive.Idparameters (assuming that the current document data has passed{% archiveDetail archive %}through tags.archiveIn the variable.) So,{% tagList %}only the tags associated with the current document will be obtained and displayed.
**Q3: Besides the tag name and link, I can