How to use the `tagDataList` tag to display documents under a specified Tag in the AnQi CMS template?

Calendar 👁️ 60

As an experienced senior CMS website operation personnel in a security company, I know that high-quality content and convenient user experience are the keys to attracting and retaining users.Tags (Tag) serve as an important dimension for content organization, not only helping users quickly find content of interest, but also an indispensable part of internal link optimization and SEO strategy.In Anqi CMS,tagDataListThe tag is a powerful tool we use to display documents under a specific tag.

This article will elaborate on how to effectively utilize the Anqi CMS template.tagDataListTags to display documents under specific tags, thus optimizing the presentation of your website content.

UnderstandingtagDataListThe role of tags.

tagDataListThe core function of the tag is to retrieve and list all documents associated with the specified tag ID.This is very useful for building tag archive pages, displaying relevant tags on article detail pages, or any scenario that requires aggregating documents by tags.By precisely calling this tag, you can provide users with a more detailed and relevant content navigation experience.

tagDataListBasic usage of tags

tagDataListThe usage of the tag is similar to other list tags, you need to define a variable to receive the returned document list, and iterate through these documents within the tag. The basic usage is to specify atagIdTo get all documents under this tag:

{% tagDataList archives with tagId="1" %}
    {% for item in archives %}
        <div class="tag-document-item">
            <a href="{{item.Link}}">{{item.Title}}</a>
            <p>{{item.Description}}</p>
        </div>
    {% endfor %}
{% endtagDataList %}

In the above example,archivesIs the variable to receive the document list.tagId="1"Indicates that we want to retrieve all documents under the tag with ID 1. If your template is currently on the details page or list page of some tag and you omit thetagIdparameter,tagDataListIt will automatically identify and retrieve the document under the current page's tag ID.

tagDataListCommon parameters of the tag

In order to more accurately control the display of the document,tagDataListThe tag provides multiple parameters for adjustment:

  • tagId: This is the core parameter to specify which label under the document to display.You can directly find the tag ID in the background management interface and assign it to this parameter.As mentioned before, omitting this parameter on the tag-related page will automatically retrieve the tag ID of the current page.
  • moduleId: If your website has multiple content models (such as articles, products), and you only want to display tag documents under specific models, you can usemoduleIdparameters to filter. For example,moduleId="1"Used to retrieve documents under the article model.
  • order: This parameter is used to specify the document sorting method. Common sorting rules include:
    • order="id desc": Sorted in reverse order by document ID (latest release).
    • order="views desc": Sorted in reverse order by views (popular documents).
    • order="sort desc": Sort in reverse order according to the custom sorting in the background.
  • limit: Used to control the number of documents returned. For example,limit="10"This parameter is very useful when you only want to display the first 10 documents. It is used when you do not need pagination and want to display a fixed number of 'recommended' or 'latest' documents.It also supports the "offset" mode, for examplelimit="2,10"Will retrieve 10 documents starting from the 2nd document.
  • type: This parameter is the key to controlling the list behavior.
    • type="list": Default value, only displaylimitThe parameter specifies the number of documents, no pagination feature is provided.
    • type="page": Enable pagination feature. When set totype="page"When, it is usually combinedpaginationTags are used together to generate a complete page navigation.
  • siteId: If your CMS is a multi-site deployment and you want to call documents under other sites, you can specifysiteIdto achieve.

Loop through and display document data

tagDataListreturnedarchivesA variable is an array of document objects. In{% for item in archives %}the loop,itemA variable represents each document in the current loop. You can accessitemvarious properties of the object to display document information:

  • item.Id: Document ID.
  • item.Title: Document title.
  • item.Link: The access link of the document.
  • item.Description: Document summary or description.
  • item.Thumb: Document thumbnail URL.
  • item.Logo: Document cover first image URL.
  • item.CreatedTime: Document creation time (timestamp format). Usually needs to be obtained throughstampToDateFiltered for formatting, for example.{{stampToDate(item.CreatedTime, "2006-01-02")}}.
  • item.Views: Document views.
  • item.CategoryId: Document category ID.
  • And other custom fields set in the document model.

Implement a complete tag archive page with pagination tags.

For a complete tag archive page, we usually need to display a large number of documents and provide pagination functions to allow users to browse. At this point, we need totagDataListoftypethe parameter to"page"and combiningpaginationTags are used together.

This is a complete example showing how to use in the tag archive pagetagDataListandpagination:

{# tag/list.html 或 tag/index.html 模板文件 #}

{# 页面标题和描述可以从当前Tag详情中获取 #}
<h1>{% tagDetail with name="Title" %}</h1>
<p>{% tagDetail with name="Description" %}</p>

<div class="tag-documents-list">
    {# 使用 tagDataList 获取当前Tag下的文档,并开启分页功能,每页显示10条 #}
    {% tagDataList archives with type="page" limit="10" %}
        {% for item in archives %}
        <div class="document-item">
            {% if item.Thumb %}
            <a href="{{item.Link}}" class="document-thumb">
                <img alt="{{item.Title}}" src="{{item.Thumb}}">
            </a>
            {% endif %}
            <div class="document-info">
                <a href="{{item.Link}}" class="document-title">
                    <h3>{{item.Title}}</h3>
                </a>
                <p class="document-description">{{item.Description}}</p>
                <div class="document-meta">
                    <span>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>阅读量:{{item.Views}}</span>
                    {# 如果需要显示分类名称,可以嵌套 categoryDetail #}
                    <span>分类:<a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></span>
                </div>
            </div>
        </div>
        {% empty %}
        <div class="no-content">
            该标签下暂无任何文档内容。
        </div>
        {% endfor %}
    {% endtagDataList %}

    {# 分页导航区域 #}
    <div class="pagination-area">
        {% pagination pages with show="5" %}
            <nav>
                <ul class="pagination-list">
                    {# 首页链接 #}
                    <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                        <a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
                    </li>
                    {# 上一页链接 #}
                    {% if pages.PrevPage %}
                    <li class="page-item">
                        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
                    </li>
                    {% endif %}
                    {# 中间页码列表 #}
                    {% for pageItem in pages.Pages %}
                    <li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
                        <a href="{{pageItem.Link}}">{{pageItem.Name}}</a>
                    </li>
                    {% endfor %}
                    {# 下一页链接 #}
                    {% if pages.NextPage %}
                    <li class="page-item">
                        <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
                    </li>
                    {% endif %}
                    {# 尾页链接 #}
                    <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                        <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
                    </li>
                </ul>
            </nav>
            <div class="pagination-summary">
                共 {{pages.TotalItems}} 条文档,{{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页。
            </div>
        {% endpagination %}
    </div>
</div>

In this example, we firsttagDetailTo get the current tag title and description. Then,tagDataListStart withtype="page"The pattern to get the document and define thelimitControl the number of items displayed per page. Next,paginationTag usagetagDataListGenerated pagination data, builds a complete and navigable pagination list, greatly enhancing the browsing experience of users on the tag archive page.

Operational personnel tips

As a website operator, use it reasonablytagDataListIt can not only enrich the display of website content but also enhance user satisfaction and SEO performance. It is recommended that when you maintain tags in the background, ensure that the tag names are descriptive and highly relevant to the content, and avoid creating too many redundant or sparse content tags.At the same time, pay attention to the TDK settings of the tab page to help the search engine better understand the themes of these aggregated pages.A high-quality tag page can effectively increase the internal link structure of a website, enhancing the overall search engine friendliness.

Frequently Asked Questions

Q1:tagDataListandarchiveListWhat are the core differences in the use of these tags?

tagDataList主要用于根据TagTo aggregate and display documents, the core filtering criterion is the tag ID associated with the document. It is very suitable for building tag archive pages or displaying related content under the same tag in the article sidebar. AndarchiveListThis is a more general document list label, which can beCategory (CategoryId)/Model (ModuleId)/Recommended attribute (Flag)/Search keyword (q)With various conditions to filter and display documents. In short, when you need to organize content based on tags, choosetagDataList; When you need to list documents based on categories or other general properties,archiveListis more appropriate.

Q2: How to automatically obtain the current Tag ID on the Tag detail page without manually specifyingtagIdthe parameter?

When you are designing the Tag detail page of AnQi CMS (usuallytag/detail.htmlor`

Related articles

How to use the `categoryDetail` tag to get category details in the AnQi CMS template?

Hello, I am your familiar old friend, a website operator who has been dealing with AnQiCMS for a long time.In daily content management and website optimization work, flexibly using AnQiCMS template tags is the key to improving efficiency and user experience.Today, let's delve deeply into a very practical tag: `categoryDetail`, and see how it helps us obtain detailed category information in the AnQiCMS template.

2025-11-06

How to use the `archiveList` tag in AnQi CMS template to call the document list?

As an expert who has been deeply involved in the field of CMS content operation for a long time, I fully understand the importance of a flexible and efficient template tag for website content display.Among them, the `archiveList` tag is undoubtedly the core tool for calling document lists in the Anqi CMS template.It can not only help us accurately filter and display various types of document content, but also combine multiple parameters to meet the diverse needs of content presentation, thus providing readers with a high-quality browsing experience.

2025-11-06

How are the basic conventions and file directory structure requirements for template creation in AnQi CMS?

As a senior CMS website operation personnel of an enterprise, I know that a clear and standardized template production convention and directory structure is crucial for the long-term operation and maintenance of the website.High-quality templates not only improve user experience, but also lay the foundation for SEO optimization.Next, I will elaborate on the basic conventions and file directory structure requirements of the Anqi CMS document for you.

2025-11-06

How to configure contact information and customize system global parameters in Anqi CMS backend?

As an expert in the operation of Anqi CMS, I understand that high-quality content cannot be separated from a stable backend configuration as a support.The contact information of the website and global system parameters, although it seems basic, is the key to user trust, brand image, and the normal operation of the website's functions.Now, I will elaborate on how to configure these important information on the Anqi CMS backend.

2025-11-06

How to use `for` loop and `if` conditional judgment tags in Anqi CMS template?

As an experienced Anqi CMS website operation personnel, I am very clear about the core role of templates in content presentation.A flexible and efficient template can not only enhance the user experience but also help us achieve accurate content placement and management.In the Anqi CMS template system, the `for` loop and `if` conditional judgment tags are the two cornerstones for building dynamic and interactive web pages.They make content no longer static text blocks, but can intelligently display according to data changes.

2025-11-06

How to use the `stampToDate` tag to format timestamps in the Anqi CMS template?

In website content management, the accuracy and aesthetics of time presentation are crucial for user experience.Whether it is the publication date of the article, the update time of the product, or the submission time of the comments, a clear and consistent date format can significantly improve the readability and professionalism of the content.AnQi CMS is an efficient and flexible content management system, deeply understanding this, and provides a powerful and simple tool for template developers - the `stampToDate` tag, which is specifically used to format timestamps into various custom date and time display formats.

2025-11-06

What is the role of the `safe` filter in the AnQi CMS template and when should it be used?

As a professional deeply familiar with the operation of Anqing CMS, I know the importance of template security and the correct presentation of content for a website.In the Anqi CMS template system, the `safe` filter plays a key role, concerning the security and display effect of the website. ### Automatic Escaping Mechanism of AnQiCMS Template AnQiCMS template system draws on the syntax characteristics of the Django template engine, one of its core design philosophies is security.

2025-11-06

How to use `truncatechars` and `truncatewords` in Anqi CMS template?

As a website operator who is well-versed in the operation of AnQiCMS, I deeply understand the subtleties of content presentation.How to elegantly handle the display of text content when building an engaging and user-friendly website experience.AnQi CMS, with its flexible class Django template engine, provides us with powerful content control capabilities, among which the text truncation feature is a commonly used tool for optimizing page layout and improving reading experience.

2025-11-06