Deep analysis of AnQi CMS: How to use it cleverly{% tagDataList %}Label precise aggregation of content?

In the world of content operation, tags (Tag) are the bridges connecting content to users.It not only helps us better organize and classify massive amounts of information, but also significantly improves the efficiency of content discovery and the SEO performance of websites.For users of AnQiCMS, fully utilizing its powerful tag function is a key step in achieving refined content operation.Today, let's delve into a highly practical template tag in Anqi CMS -{% tagDataList %}Understand how it helps us retrieve all associated documents under a specific tag, thereby building a more attractive and valuable content aggregation page for users.

Tag, the intelligent index of content management

In AnQi CMS, tags are not just simple keywords.It represents a flexible content association mechanism that allows content to cross traditional classification boundaries, aggregating multidimensionally based on themes, keywords, or characteristics.From adding one or more tags to the content when you publish documents in the background, to finally intelligently linking the documents tagged with the same tag on the frontend page, Anqi CMS provides seamless and efficient support.As mentioned in the document, the "Document Tag Management" of Anqi CMS can view and manage all document tags.The document tags are not categorized by type and model, the same tag can be assigned to documents of different content models at the same time, which gives the content great flexibility and interconnectivity.

{% tagDataList %}: Conductor of tag content

When we talk about how to get all related documents under a specific tag{% tagDataList %}The tag is undoubtedly the core tool for this task. It can filter and return all documents associated with the specified tag 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 interpret it in detail{% tagDataList %}Usage and its main parameters:

A glimpse at the basic usage:

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

Here, archivesIs a variable name you define, used for storage{% 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 tag (such astag/list.htmlortag/index.html), Anqi CMS will intelligently identify the Tag ID of the current page, at this time you do not need to explicitly pass intagIdThe parameter will automatically retrieve and use the current page's Tag ID to query the document.
    • 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 an independent special topic page, you need to manually go throughtagId="[Tag ID]"Specify the label ID you want to retrieve the content for. For example, to retrieve all documents under the "Marketing" label with ID 5, you can usetagId="5".
  2. moduleId: Limit the scope of the content model

    • The AnQi CMS supports flexible content models, such as the "article model" (usuallymoduleId="1"), and the "product model" (usuallymoduleId="2")et al. If you only want to get the label-related documents under a specific model, you can usemoduleId="[模型ID]"to filter. For example,moduleId="1"it will only return the documents under the 'Article Model', ensuring the accuracy of the content.
  3. orderDefine the sorting method of the content

    • The order in which content is presented is crucial for the user's browsing experienceorderThe 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 the most recently published documents are at the top.
      • order="views desc"Sort the documents by the number of views in descending order, displaying the most popular documents.
      • order="sort desc": Arrange in descending order according to the custom sorting value on the back end, allowing you to manually adjust the priority of important content.
  4. limit: Control the number of documents displayed.

    • This parameter is used to limit the number of documents returned each time a query is made. For example,limit="10"only 10 documents will be displayed.
    • It is worth mentioning,limitIt also supports the "offset mode", which islimit="[起始偏移量],[数量]"For example,limit="2,10"Indicates starting from the second document (index starting from 0), retrieving 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 way the list is presented.
      • type="list"It 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 AnQi CMS's{% pagination %}tags to render pagination navigation,providing a better browsing experience for users.
  6. siteId:Data isolation in a multi-site environment

    • For users of the security CMS deployed on multiple sites,siteIdThe parameter ensures that you can call across sites or limit the call to the current site.In most cases, 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 collection of obtained documents as an array object (we name itarchivesReturn. You can use{% for item in archives %}to iterate over each document object. 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 publication time (usually needs to be配合{{stampToDate(item.CreatedTime, "2006-01-02")}}Format
  • item.Views: Document views
  • item.CategoryId: Document category ID

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

Practice exercise: A typical Tag list page template example

Assuming we are building a Tag detail pagetag/list.htmlI hope to display all articles under this tag and support pagination. Below is a simplified but complete example code:

<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>