How to implement sorting tags such as `{% tagList %}` by popularity (for example, by the number of associated documents)?

Calendar 👁️ 53

As an experienced website operation expert, I know that tag management is important for content organization and user discovery.In an efficient content management system like AnQiCMS, how to intelligently display tags, especially sorting by popularity, is a concern for many content operators.Today, let's delve deeper into{% tagList %}Tags and their ability and challenges in implementing hot tag sorting.

Mining tag potential: An overview of tag functions in AnQi CMS.

In Anqi CMS, tags (Tags) are a powerful content association tool.It is not like classification that has a hierarchical structure, but is more flexible in connecting the content of different categories even different models.By tagging documents, products, and other content, we can make it easier for users to discover related content through tags, greatly enhancing the cross-referencing and discoverability of website content.

AnQi CMS provides several core template tags related to tags:

  • {% tagList %}: Used to obtain and display the tag list on the website.
  • {% tagDetail %}: Used to obtain the detailed information of a single tag.
  • {% tagDataList %}: Used to retrieve the document list associated with a specific tag.

These three tags together form the foundation of the Anqi CMS tag function, they usually play a role in the website sidebar, article bottom, tag cloud page, etc., guiding users to explore the website content in depth.

Core Challenge:{% tagList %}How do tags implement sorting by popularity?

Many operators would like to display the 'Hot Tags', which are those tags referenced by the most documents.This not only reflects the trend of the website's content, but also helps users quickly find the most popular topics of the moment.However, when we carefully examine the security CMS provided{% tagList %}When documenting tags, you will find a key restriction:

Current{% tagList %}Tags mainly support the following parameters:

  • itemId: Retrieve associated tags based on the specified document ID.
  • limit: Limit the number of returned tags.
  • letter: Filter tags by alphabetical index.
  • categoryId: Filter tags belonging to a specific category.
  • siteIdSpecify the site in a multi-site environment.

It is obvious that in the current version,{% tagList %}Tagged,does not provide a parameter directly (such asorder="document_count desc"or a similar instruction to sort the tag list by the number of associated documentsSimilarly,{% tagList %}in the loop, each item's (item) available field also only containsId/Title/Link/Description/FirstLetter/CategoryIdbasic information is not provided directlyDocumentCountsuch fields as (number of associated documents).

This means that we cannot directly obtain a list of tags sorted by popularity (number of associated documents) through simple configuration of template tags.

Implement a substitute strategy for 'Popular Tags'

Although{% tagList %}The tag itself does not directly support sorting by popularity, but as a senior operation expert, we can always find some workaround strategies to try to meet this need as much as possible.These strategies have different applicability depending on the scale of the website and the level of technology investment.

Strategy 1: Backend expansion or custom development (recommended long-term solution)

There is no doubt that the most thorough and efficient solution is to customize the development on the backend of Anqi CMS.This approach can fundamentally solve the problem and provide ** performance and flexibility.

  1. modifyTagData model:In AnQi CMS'sTagAdd one in the data model:DocumentCount(or similar name) field.
  2. Add counting logic:Synchronize updates to related tags when content is published, modified, or deleted.DocumentCountfield. It can also be updated through scheduled tasks or on-demand calculations.
  3. extensiontagListlabel logic:processing on the backend{% tagList %}when labeling, increase the ability toorderParameter support, allows input to be passedorder="document_count desc"Such values, and sort the database query based on this parameter. At the same time, ensure that the data returned to the template includesDocumentCountfield.

Once the backend supports this feature, the invocation of the front-end template will become very concise and efficient:

{# 假设后端已支持按关联文档数量排序 #}
{% tagList hotTags with limit="10" order="document_count desc" %}
    <ul class="hot-tags-list">
    {% for item in hotTags %}
        <li><a href="{{item.Link}}" title="{{item.Title}} ({{item.DocumentCount}}篇)">{{item.Title}}</a></li>
    {% empty %}
        <li>暂无热门标签</li>
    {% endfor %}
    </ul>
{% endtagList %}

Strategy two: Manually maintain the 'Hot Recommendations' tag (suitable for websites with a small number of tags or infrequent updates)

If the number of tags on the website is not many, or the definition of "hot" is not entirely dependent on the number of related documents, operators can manually maintain "simulated" hot tags through the background.

  1. Tag Management:In the AnQi CMS backend, regularly observe the number of documents associated with each tag in the "Document Tag" management interface (although it cannot be sorted, you can view them one by one).
  2. Filter or set:
    • Method one (using existing fields):If the label model has an editable "sort value" or "recommendation attribute" field, you can manually set the sort value of popular tags or mark them as "recommended". Then,{% tagList %}When the tag is called, throughorder="sort_field desc"Or if supportedflag="recommended"To filter and sort. However, according to the current document, the tag itself does not seem to be as rich as the document suggestsflagproperty orsortfield.
    • Method two (create a fixed list):Create a custom text list containing a few "hot tags" and configure it either hard-coded in the template or through the custom parameters of the "system settings", and then update it manually. This

Related articles

How is the link of the document tag automatically generated in the front-end template?

AnQiCMS (AnQiCMS) has always been committed to providing both efficient and flexible solutions in content management. Among them, the document tag (Tag) serves as an important tool for content organization and SEO optimization. The link generation mechanism in the front-end template even reflects the exquisite design of the system.As an experienced website operations expert, I am well aware of the importance of a clear and friendly URL structure for user experience and search engine rankings.Today, let's delve into how Anqi CMS automates the generation of these valuable tag links.### One, Tag (Tag) is in

2025-11-06

How to determine whether the current page is the detail page of a document tag and perform special layout?

As an experienced website operations expert, I know that how to flexibly customize the page layout in a content management system is crucial for improving user experience and optimizing SEO.AnQiCMS (AnQiCMS) with its powerful template engine and rich tag features, provides us with the tool to achieve this goal.Today, let's delve deeply into a common and practical requirement: how to determine whether the current page in Anqi CMS is a detail page of a document tag and apply a unique layout to it.

2025-11-06

How to design and display a beautiful tag cloud (Tag Cloud) on a frontend page?

AnQiCMS is an enterprise-level content management system developed based on the Go language, which is favored by many small and medium-sized enterprises and content operation teams for its high efficiency, customization and ease of expansion.As an expert in website operations for many years, I deeply understand the importance of content display strategy for attracting users and improving SEO performance.Today, let's talk about how to design and display a beautiful and practical Tag Cloud on the AnQiCMS frontend page.

2025-11-06

How to implement the `limit` parameter of the `tagList` tag to start displaying from the Nth tag?

As an expert deeply familiar with the operation of Anqing CMS content, I am delighted to delve into the巧妙用法 of the `limit` parameter in the `tagList` tag, especially how to achieve the advanced function of displaying from the Nth tag.This can bring great flexibility to content layout and user experience in actual website operations.

2025-11-06

How to use document tags to enhance the internal link structure of website content and improve user navigation experience?

## How to cleverly use AnQi CMS document tags to weave a content link network and optimize user exploration experience As an experienced website operations expert, I know that the core value of a content management system (CMS) is not only in the efficiency of content publishing, but also in how to make these contents easily discovered by users and generate greater value.AnQiCMS (AnQiCMS) provides a strong support for small and medium-sized enterprises and content operators with its concise and efficient architecture.Today, let's delve deeply into a seemingly simple yet potentially powerful feature in Anqi CMS - **Document Tags**

2025-11-06

How to efficiently apply various data filters in Anqi CMS templates?

AnQi CMS, as an enterprise-level content management system built based on the Go language, has won the favor of many small and medium-sized enterprises and content operators with its efficient, secure, and flexible features.In daily content management and front-end display, we often need to process and present data in a fine-grained manner, which cannot be separated from the powerful data filtering function in the template.This article will delve into how to efficiently apply various data filters in the AnQiCMS template, making your content display more expressive and practical.###

2025-11-06

What are some advanced usage techniques for the AnQi CMS filter chaining call?

As an experienced website operation expert, I fully understand the importance of content presentation and processing efficiency in daily work for website operation.AnQiCMS (AnQiCMS) with its flexible and efficient characteristics, has provided us with many conveniences in content management.Among them, the filtering function provided by the template engine, especially the **chained filter call**, is a powerful tool for us to achieve fine-grained content presentation and efficient template development.Today, let's delve into some advanced usage techniques of the Anqi CMS filter chaining call

2025-11-06

How to set a reliable default value for empty variables in Anqi CMS template?

As an experienced website operations expert, I know that handling null variables is the key to ensuring the quality of website content and user experience when building and maintaining website templates.In AnQiCMS such a flexible and efficient content management system, the flexible use of template variables is its strong point, but at the same time, how to elegantly set reliable default values for possibly empty variables to avoid ugly blank spaces on the page or functional anomalies is an art worth in-depth exploration.

2025-11-06