In AnQi CMS, content organization can not only be achieved through traditional classification methods, but the flexible "Tag" mechanism also provides a wide range of space for content association and user search.When you want to display all documents under a specific tag in a certain area of the website, such as the sidebar, related recommendation module, or even a dedicated Tag aggregation page, Anqi CMS provides a powerful and intuitive template tag to make this process effortless.
This article will delve into how to obtain and loop through all document lists under a specific Tag (label) in the Anqi CMS template through simple code, helping you better utilize the tag feature and enhance the organization of website content and user experience.
The role of Tag (Tag) in AnQi CMS
In AnQi CMS, tags are a flexible content organization tool.Tags can cross different content models (such as articles, products, etc.) for association, unlike a strict classification system.This means that an article titled 'Anqi CMS User Manual' and a product named 'Anqi CMS Training Service' can both be tagged with 'Anqi CMS'.This flexibility allows content to be associated and discovered from multiple dimensions, greatly enriching the website's navigation and SEO potential.
Core Weapon:tagDataListtags
To obtain the document list under a specific Tag, we mainly rely on the AnQi CMS providedtagDataListTemplate tags. This tag is specifically used to retrieve a collection of documents associated with a specific tag from the database.
tagDataListBasic structure of tags
tagDataListThe use of tags follows the common syntax of the AnQi CMS template engine, which requires a variable name to hold the retrieved document list, and defines the loop output logic between{% tagDataList ... %}and{% endtagDataList %}.
The basic syntax is as follows:
{% tagDataList 变量名称 with 参数 %}
{% for item in 变量名称 %}
{# 在这里输出文档的各项信息 #}
{% endfor %}
{% endtagDataList %}
Among them,变量名称can be any name you define, such asarchives/tagArticlesetc.itemis infora loop represents a temporary variable for each document.
Key parameter parsing
tagDataListSupport for multiple parameters, allowing you to finely control which Tags' documents you want to retrieve, and how to sort and display them.
tagId(Required):This is the specific parameter you want to get under which Tag of documents. You can directly fill in the numerical ID of the Tag, for example,tagId="1". If you are on a Tag detail page (for example,tag/list.htmlUse this tag, and if you want to retrieve documents under the current page Tag, you do not need to specify.tagIdIt will automatically read the current page Tag ID.moduleId(Optional):If you only want to retrieve documents associated with a specific model (such as an article model, product model) under the Tag, you can use this parameter. For example,moduleId="1"Represents only retrieving documents under the article model.type(Optional):Controls the display style of the list.type="list"(Default value): BylimitThe number of documents to display as specified by the parameter, without pagination features.type="page":