As an experienced website operations expert, I am well aware of the importance of tag management for content organization and user discovery.How to more intelligently display tags, especially in order of popularity, in an efficient content management system like AnQiCMS, is a concern for many content operators.{% tagList %}Tags and their ability and challenges in implementing hot tags sorting.
Mining the potential of tags: An overview of the tag feature in Anqi CMS.
In AnQi CMS, tags (Tags) are a powerful content association tool.It does not have a hierarchical structure like classification, but is more flexible in connecting the content of different categories and even different models.By tagging documents, products, and other content, we can facilitate users in discovering 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 %}[en] Used to retrieve the list of documents 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's sidebar, article footer, tag cloud page, etc., guiding users to explore the website's content in depth.
Core Challenge:{% tagList %}How do tags achieve sorting by popularity?
Many operators would like to display '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 at the moment.{% tagList %}When labeling documents, you will find a key restriction:
The 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 that belong to a specific category.siteIdSpecify a site in a multi-site environment.
It is evident in the current version,{% tagList %}in the tag,and does not provide a parameter directly (such as)order="document_count desc"Sort the tag list by the number of associated documents using a command like (or similar commands)Similarly,{% tagList %}in the loop body, the available fields of each tag item also only containId/Title/Link/Description/FirstLetter/CategoryId[Basic information, not provided directly]DocumentCount[Fields such as (number of associated documents)]
This means that we cannot directly obtain a sorted tag list by popularity (number of associated documents) through simple configuration of template tags.
Implement an alternative strategy for "Hot Tags"
Although{% tagList %}The tag itself does not directly support sorting by popularity, but as a senior operations expert, we can always find some workaround strategies to as much as possible meet this requirement.These strategies have different applicability depending on the scale of the website and the level of technical 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 development on the backend of Anqi CMS.This method can fundamentally solve the problem and provide ** performance and flexibility.
- Modify
TagData model:In the Anqi CMS.TagAdd one in the data modelDocumentCountThe field of (or similar names). - Add counting logic:Synchronize the related tags when content is published, modified, or deleted.
DocumentCountField. It can also be updated through scheduled tasks or on-demand calculations. - Extension
tagListTag logic:Processing on the backend{% tagList %}When adding tags,orderParameter support, allowing inputorder="document_count desc"such values, and sort the database query according to this parameter. At the same time, ensure that the data returned to the template includesDocumentCountfield.
Once the backend supports this feature, the frontend template calls 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 'Hot Recommendations' tags (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 "popular
- Label Management:In the 'Document Labels' management interface of the Anqi CMS backend, regularly observe the number of documents associated with each label (although it cannot be sorted, you can view them individually).
- 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 labels or mark them as 'recommended'. Then,
{% tagList %}Label invocation, throughorder="sort_field desc"(if supported) orflag="recommended"(if supported) to filter and sort. However, according to the current document, the label itself does not seem to have as richflagproperties orsortfield. - Method Two (Create a Fixed List):Create a custom text list containing a few "hot tags" and hard-code it in the template or configure it through the custom parameters of the "system settings", then update it manually.
- 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 labels or mark them as 'recommended'. Then,