How to display the associated tags of the `tagList` and implement a tag cloud effect?

Calendar 👁️ 74

How to make good use of AnQiCMS'stagListTag, easily realize document association and tag cloud display

In website content operation, tags (Tag) play a crucial role.They can not only help users find the content they are interested in quickly, improve the convenience of site navigation, but also optimize the search engine's understanding of website content through the aggregation of keywords, thus bringing better SEO performance.AnQiCMS has fully considered this requirement, built-in powerful tag features, and provided flexible template tagstagListLet us easily display the associated tags of the document, even creating an eye-catching tag cloud effect.

This article will lead everyone to understand in depthtagListHow to use tags, from basic related tag display to how to achieve a visually stunning tag cloud effect, making your website content organization clearer and improving the user experience to a new level.

Core function analysis:tagListThe power of tags

tagListIs a very practical tag in the AnQiCMS template system, it is mainly used to get the tag list related to the document, or to get all the tags of the site.Its flexibility lies in being able to configure different parameters to meet the needs of various label displays.

UsetagListThe basic syntax of tags is usually like this:{% tagList tags with limit="10" %}Here, tagsIs the variable name we define for the list of tags obtained, you can name it according to your preference.limit="10"This indicates that we want to retrieve up to 10 tags.

This tag can retrieve the ID of each tag (Id), Title (Title) and link (Link), Description (Description), the index letter (FirstLetter) and the ID of the category it belongs to (CategoryIdThis information and more. Through this information, we can build various label display forms.

Show the associated tags of the document: step by step implementation.

The most common application scenario for tags is at the bottom of articles or product detail pages, displaying tags related to the current content.This can guide users to discover more related content and extend the time they stay on the website.

We need to display related tags on the document detail page, we need to use the corresponding template file (such asarchive/detail.htmlor a custom document detail template)tagListtags and specify the ID of the current document.

For example, you can write the code like this in your document detail template:

{# 假设当前页面是文档详情页,archive 是文档详情对象 #}
<div class="article-tags">
    <strong>相关标签:</strong>
    {% tagList tags with itemId=archive.Id limit="10" %}
        {% for item in tags %}
            <a href="{{ item.Link }}" title="{{ item.Title }}" class="tag-item">{{ item.Title }}</a>
        {% empty %}
            <span>暂无相关标签。</span>
        {% endfor %}
    {% endtagList %}
</div>

In this code block:

  • We passitemId=archive.IdParameters, explicitly telltagListTags, what we want to get isarchivethe tags associated with this document object.archive.IdIt will automatically retrieve the unique identifier of the current document.
  • limit="10"The number of displayed tags is limited to avoid too many tags occupying the page space.
  • {% for item in tags %}Loop through the obtained tag list. EachitemRepresent a label object.
  • {{ item.Link }}and{{ item.Title }}Links and display names used to generate tags. When users click these links, they can jump to the exclusive page of the tag, where they can view more content with the same tag.
  • {% empty %}The statement is a thoughtful design, when the document is not associated with any tags, it will display "No related tags." to avoid blank pages.

By the above code, your document detail page can clearly display the tags closely related to the current document, greatly enhancing the user's content discovery experience.

Create a tag cloud effect: optimize user browsing experience

Label clouds are a visually striking way of displaying tags, presenting them through different font sizes, colors, or arrangements. Typically, the more popular a tag (or the more associated documents it has), the more prominent it appears in the cloud. Although AnQiCMS'stagListThe tag itself does not directly provide a parameter like "tag weight" to automatically adjust size, but we can cleverly achieve a similar tag cloud effect by getting all-site tags and combining them with frontend styles.

To create a tag cloud, we usually place it in the website sidebar, footer, or a dedicated tag list page (for exampletag/index.html) is displayed. The first step in implementing a tag cloud is to obtain the list of tags for the entire site. At this point, we do not need to specifyitemIdparameters, or explicitly specifyitemIdis set to"0".

The following is a simple tag cloud code example:

<div class="tag-cloud-container">
    {% tagList allTags with itemId="0" limit="50" %} {# 获取全站最多50个标签 #}
        {% for item in allTags %}
            <a href="{{ item.Link }}" title="包含 {{ item.Title }} 的文档" class="tag-cloud-item tag-size-{{ forloop.Counter % 5 + 1 }}">
                {{ item.Title }}
            </a>
        {% endfor %}
    {% endtagList %}
</div>

In this example:

  • itemId="0"indicationstagListThe tags obtained are all site tags, not tags of specific documents.
  • limit="50"The number of tags displayed in the tag cloud is limited, which can be adjusted according to the page layout and requirements.
  • To simulate different sizes, we utilizedforloop.Counter(the current loop index, starting from 1) to generate a simple style classtag-size-X. You can use CSS totag-size-1totag-size-5Define different font sizes, colors, or boldness to create visual differentiation. For example:
/* 示例 CSS 样式,实际项目中请根据需要调整 */
.tag-cloud-item {
    display: inline-block;
    margin: 5px;
    padding: 3px 8px;
    border-radius: 3px;
    text-decoration: none;
    color: #555;
    background-color: #f0f0f0;
    transition: all 0.3s ease;
}
.tag-cloud-item:hover {
    background-color: #e0e0e0;
    color: #333;
}
.tag-size-1 { font-size: 14px; }
.tag-size-2 { font-size: 16px; font-weight: bold; }
.tag-size-3 { font-size: 18px; color: #007bff; }
.tag-size-4 { font-size: 20px; font-weight: bold; color: #28a745; }
.tag-size-5 { font-size: 22px; font-weight: bolder; color: #dc3545; }

By combining this, you can achieve a dynamic and visually appealing tag in AnQiCMS

Related articles

How to build a complex search interface for product filtering or property filtering using the `archiveFilters` tag?

In the era of content explosion, when users visit websites, they often hope to quickly find the content they are interested in.Whether it is browsing a large number of products on e-commerce platforms or looking for housing that meets your preferences on real estate websites, a powerful and easy-to-use filtering and search interface is the key to improving user experience. AnQiCMS (AnQiCMS) knows this and provides a powerful `archiveFilters` tag for this purpose.This tag can help you easily build a complex product or property filtering interface, making your website content more discoverable and interactive

2025-11-08

How does the `archiveParams` tag display custom field data of the document on the frontend page?

In AnQi CMS, the flexibility of content is one of our core advantages for website operation and content management.In addition to standardized fields such as titles and text, we often need to add specific custom information for different types of content, such as the 'brand', 'model', and 'origin' of products, or the 'author' and 'source' of articles, etc.These custom fields greatly enrich the dimensions of content display, but how to accurately and flexibly present these meticulously entered backend data on the front-end page is an important consideration during template development. At this time

2025-11-08

How to use the `archiveList` tag's `type="related"` feature to display related article recommendations?

On your website, when visitors finish reading an article, if they can see related content in time, it not only can significantly improve the user experience, reduce the bounce rate, but also can effectively increase the page views and stay time on the website.AnQi CMS provides a very convenient tag: `archiveList`,配合其`type="related"` attribute, it can easily realize this function.###

2025-11-08

How to implement the previous/next document function using `prevArchive` and `nextArchive` tags?

When you operate a website, providing a smooth reading experience for users is one of the key factors in enhancing website stickiness.When a user finishes reading a document, if they can easily jump to the previous or next related article, it will undoubtedly greatly increase their stay time on your website.AnQiCMS (AnQiCMS) understands this and provides very intuitive and powerful `prevArchive` and `nextArchive` tags to help you easily implement this feature.

2025-11-08

How to retrieve and display the details of a specific `tagDetail` tag?

AnQiCMS (AnQiCMS) provides a series of powerful template tags to help website operators efficiently display content.Among them, the `tagDetail` tag is a key tool for obtaining and displaying specific tag details.Whether it is to build a beautiful tag detail page or to refer to related data of tags on other pages, `tagDetail` can provide a flexible and intuitive solution.

2025-11-08

How does the `tagDataList` tag display all document lists under a specific tag?

In Anqi CMS, managing and displaying content, the tag (Tag) is undoubtedly a very practical tool.It can help us organize documents more flexibly, realize multi-dimensional content aggregation, and greatly benefit the improvement of the website's SEO performance and user experience.When we need to display a list of all documents under a specific tag page, or at any location on the website, the `tagDataList` tag is an indispensable tool.###

2025-11-08

How to display the comment list and pagination on the article detail page with the `commentList` tag?

In AnQi CMS, the comment list on the article detail page is an important component for enhancing user interaction and content vitality.To naturally and smoothly display these comments and achieve a friendly pagination experience, we need to cleverly use the `commentList` and `pagination` template tags.Next, let's take a look at how to implement the display and pagination of comments on the article detail page.

2025-11-08

How to quickly generate a customizable website guestbook form with the `guestbook` tag?

In website operation, interacting with visitors and collecting feedback is an important link to improve user experience and obtain valuable information, and the comment form is the core tool to achieve this goal.AnQiCMS (AnQiCMS) fully understands its importance and provides the `guestbook` tag for users, allowing you to easily and flexibly build a powerful and highly customizable website guestbook form.

2025-11-08