In AnQi CMS, content organization can not only be achieved through traditional classification methods, but also the flexible "Tag" mechanism provides a wide 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 powerful and intuitive template tags to make this process effortless.

This article will deeply explore how to use simple code in Anqi CMS templates to retrieve and loop through the list of all documents under a specific Tag (label), helping you better utilize the tag feature to enhance the organization of website content and user experience.

The role of (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.) to associate with different content.This means an article about the 'AnQi CMS User Manual' and a product of 'AnQi CMS Training Service' can 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:tagDataListTag

To obtain the document list under a specific Tag, we mainly rely on the provided by AnQi CMStagDataListTemplate tag. This tag is specifically used to retrieve a collection of documents associated with a specific tag from the database.

tagDataListBasic structure of the tag

tagDataListThe use of tags conforms to the common syntax of AnQi CMS template engine, it requires a variable name to carry the obtained document list, and define the loop output logic between a pair of{% tagDataList ... %}and{% endtagDataList %}.

Basic syntax is as follows:

{% tagDataList 变量名称 with 参数 %}
    {% for item in 变量名称 %}
        {# 在这里输出文档的各项信息 #}
    {% endfor %}
{% endtagDataList %}

Among them,变量名称Can be any name you customize, for example,archives/tagArticlesetc.itemIt isforThe temporary variable representing each document in the loop.

Key parameter parsing

tagDataListTags support multiple parameters, allowing you to finely control which documents under which Tags to retrieve, as well as how to sort and display them.

  • tagId(Required):This is the key parameter you want to get under which Tag of the document. You can directly enter the numeric ID of the Tag, for exampletagId="1". If you are on a Tag detail page (such astag/list.html) Use this tag and you want to retrieve the documents under the current page Tag, you do not need to specifytagId, it will automatically read the Tag ID of the current page.
  • moduleId(Optional):If you only want to retrieve documents associated with a specific model (such as an article model, product model) under this Tag, you can use this parameter. For example,moduleId="1"It indicates that only the documents under the article model should be retrieved.
  • type(Optional):Controls the display style of the list.
    • type="list"(Default): BylimitThe number of documents to display as specified by the parameter, without pagination features.
    • type="page":