AutoCMS Deep Analysis: How to Use It Smartly{% tagDataList %}Tag Precision Aggregation of Content?

In the world of content operation, tags (Tag) are the bridges connecting content with users.It can not only help us better organize and classify massive amounts of information, but also significantly improve the efficiency of content discovery and the SEO performance of the website.For users of AnQiCMS, fully utilizing its powerful tag function is a key step in achieving refined content operation.{% tagDataList %}Understand how it helps us retrieve all related documents under a specific tag, thereby building a more attractive and valuable content aggregation page for users.

Tag, an intelligent index for content management

In the Auto CMS, a tag is not just a simple keyword.It represents a flexible content association mechanism that allows content to cross traditional classification boundaries and aggregate multidimensionally based on themes, keywords, or characteristics.From adding one or more Tags to the content when you publish documents in the background, to intelligently linking documents with the same Tag on the front-end page, Anqi CMS provides seamless and efficient support.As mentioned in the document, the 'Document Tag Management' in AnQi CMS can view and manage all document tags.The document tags are not classified by categories and models, the same tag can be assigned to documents of different content models at the same time. This gives the content great flexibility and interconnectivity.

{% tagDataList %}:Tag content director

When we talk about how to get all associated documents under a specific tag,{% tagDataList %}The label is undoubtedly the core tool for this task.It can filter and return all documents associated with the specified tag ID based on your label ID (usually referred to as “archive” in AnQiCMS).The strength of this tag lies in its flexibility and controllability, allowing you to accurately display content according to different business needs.

Let's delve into the details of:{% tagDataList %}Usage and its main parameters:

A glimpse at the basic usage:

{% tagDataList archives with tagId="1" %}
    {# 循环遍历文档内容 #}
{% endtagDataList %}

Here,archivesIt is a variable name you define, used to store{% tagDataList %}the document list returned by the tag.

Detailed explanation of core parameters, grasp the pulse of content acquisition:

  1. tagId: Specify the unique identifier of the tag.

    • This is{% tagDataList %}The most core parameter. When you are on the detail page of a label (for exampletag/list.htmlortag/index.html), Anqi CMS will intelligently identify the Tag ID of the current page, at which time you do not need to explicitly pass intagIdParameters, tags will be automatically retrieved and used to query documents with the current page's Tag ID.
    • However, if you want to display content under a specific tag on other pages, such as a module on the homepage, the sidebar of an article detail page, or a standalone special topic page, you need to do it manually.tagId="[Tag ID]"Specify the tag ID of the content you want to retrieve clearly. For example, to retrieve all documents under the 'Marketing' tag with ID 5, you can usetagId="5".
  2. moduleId: Limit the scope of the content model

    • English CMS supports flexible content models, such as “article model” (usuallymoduleId="1") and “product model” (usuallymoduleId="2")et al. If you only want to get the associated document tags under a specific model, you can usemoduleId="[模型ID]"to filter. For example,moduleId="1"will only return documents under the "article model", ensuring the accuracy of the content.
  3. order:Define the sorting method of the content

    • The order in which content is presented is crucial for the user's browsing experience.orderThe parameter allows you to customize the sorting rules of the document. Common sorting methods include:
      • order="id desc":Sorted in descending order by document ID, usually meaning that the most recently published documents are at the top.
      • order="views desc":Documents are displayed in descending order of views according to the document, showing the most popular documents.
      • order="sort desc":Documents are displayed in descending order of custom sorting values on the backend, allowing you to manually adjust the priority of important content.
  4. limit:Control the number of displayed documents

    • This parameter is used to limit the number of documents returned in each query. For example,limit="10"only 10 documents will be displayed.
    • It is worth mentioning that,limitIt also supports "offset mode", i.e.limit="[起始偏移量],[数量]"For example,limit="2,10"This indicates starting from the second document (index starting from 0) and getting the next 10 documents, which is very useful in some special layouts.
  5. type: Switch the display type of the list

    • typeThe parameter defines the display style of the list.
      • type="list"Is the default value, it will return directly.limitThe parameter specifies the number of document lists.
      • type="page"It means you want to build a paginated document list. When usingtype="page"When, you also need to combine the security CMS of{% pagination %}tags to render pagination navigation, providing users with a better browsing experience.
  6. siteId: Data isolation in a multi-site environment

    • For CMS users who have deployed multiple sites,siteIdThe parameter can ensure that you can call data across sites or limit it to the current site.In general, if you only manage one site, you do not need to fill in this parameter, the system will handle it by default.

Traverse the document object to extract the required information:

{% tagDataList %}The tag will take the set of documents obtained as an array object (we name it)archives)Return. Within the tag, you can use{% for item in archives %}a loop to process each document object one by one. Eachitemrepresents an independent document and contains rich field information, such as:

  • item.Id: Document ID
  • item.Title: Document Title
  • item.Link: Document Link
  • item.Description:Document introduction
  • item.Logooritem.Thumb:Document cover image or thumbnail
  • item.CreatedTime:Document release time (usually requires){{stampToDate(item.CreatedTime, "2006-01-02")}}formatted)
  • item.Views:Document Views
  • item.CategoryId:Document category ID

etc., you can flexibly call according to your actual needs.

Practice Exercise: An example of a typical Tag list page template

Suppose we are building a Tag detail pagetag/list.htmlEnglish translation: I hope to display all articles under this Tag and support pagination. Here is a simplified but fully functional example code:

`twig {# Page TDK settings, ensure SEO friendly #} {% tdk seoTitle with name=“Title” siteName=true %} {% tdk seoKeywords with name=“Keywords” %} {% tdk seoDescription with name=“Description” %} <!DOCTYPE html>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ seoTitle }}</title>
<meta name="keywords" content="{{ seoKeywords }}">
<meta name="description" content="{{ seoDescription }}">
<link rel="stylesheet" href="{% system with name='TemplateUrl' %}/css/style.css">

{# 引入公共头部 #}
{% include "partial/header.html" %}

<div class="container">
    {# 面包屑导航,提升用户体验 #}
    {% breadcrumb crumbs %}
    <nav class="breadcrumb">
        {% for item in crumbs %}
            <a href="{{ item.Link }}">{{ item.Name }}</a>
            {% if not forloop.Last %} &gt; {% endif %}
        {% endfor %}
    </nav>
    {% endbreadcrumb %}

    <h1 class="tag-title">标签:{% tagDetail with name="Title" %}</h1>