How to list all relevant document lists under a specified Tag tag?

Calendar 👁️ 62

As an experienced website content expert in the operation of Anq CMS, I deeply understand the readers' desire for efficient content management and display.Tags act as an important means of content organization, which can greatly enhance the discoverability and user experience of content.In Anqi CMS, correctly utilizing the tag function can help your website achieve more refined content aggregation and distribution.

This article will elaborate on how to list all related document lists under the specified Tag label in Anqi CMS, helping you better organize and present website content.

Understand the tag function of AnQi CMS in depth

The AnQi CMS tag feature is aimed at providing flexible topic classification for content.Tags are more like keywords or thematic words of the content, allowing a document to be associated with multiple tags, thus achieving cross-references between content across different dimensions.The background document tag management function allows you to create, edit, and manage these tags and apply them to various documents such as articles, products, and more.This mechanism makes content organization more flexible and also provides users with diverse content exploration paths.

Core template tag:tagDataListUsage of

AnQi CMS provides a special template tag to list all relevant documents under the specified Tag tag on the website front-endtagDataList. This tag is the key tool for implementing this feature, which can retrieve and return all associated document lists based on the provided tag ID.

tagDataListTag syntax and parameters

tagDataListThe basic usage of tags is:{% tagDataList archives with tagId="1" %}...{% endtagDataList %}. Here,archivesIs a custom variable name that will carry the document collection retrieved from the tag.

The tag supports multiple parameters to meet different content display requirements:

  • tagId: Specify the tag IDThis is the most core parameter, used to specify which tag's documents you want to list. For example,tagId="1"It will list all documents under the tag with ID 1. It should be noted that if not specifiedtagIdIn the case, this tag will automatically attempt to read the TagID of the current Tag page, which is very convenient when building the tag detail page.

  • moduleId: Filter by content modelIf you want to list documents under specific content models (such as articles, products) only, you can use this parameter. For example,moduleId="1"it will only retrieve documents under the article model.

  • order: Sorting rulesYou can set the document sorting method according to your needs, for exampleorder="id desc"Sorted by the most recent release,order="views desc"Sorted by views from high to low, ororder="sort desc"sort by backend custom sorting.

  • limitControl the number of displayed items.This parameter is used to limit the number of documents returned.limit="10"It will display 10 documents. It also supportsoffsetpatterns, such aslimit="2,10"means starting from the second document and retrieving 10 items.

  • type: List type typeThe parameter determines the display behavior of the list. The default value islistIn this case,limitThe parameter will accurately control the number of documents returned. If set totype="page"It indicates that you want to enable the pagination feature, followed bypaginationtags to build a complete pagination interface.

  • siteId: Multi-site callUnder the multi-site management mode of AnQi CMS, if you need to call data from other sites, you can specifysiteIdthe parameter to achieve this. In most cases, this parameter does not need to be filled in.

tagDataListThe tag will return aarchivesarray object, you need to go throughforto traverse and display each document. Eachitemobject (that is, each document in the array) contains rich field information, such as:Id(Document ID),Title(Document Title),Link(Document Link),Description(Document description),Logo(Cover main image),Thumb(thumbnail),CreatedTime(creation time),Views(Page views) and others. You can flexibly choose these fields to build the document list according to the template.

Practical demonstration: List the document list under the specified Tag.

In most cases, the most common scenario for displaying the document list under a specified tag is the tag detail page (tag/list.htmlortag_list.html) or displaying related recommendations in the sidebar or bottom area of some page.

Example 1: Displaying paginated document lists on the tag detail page

Assuming you are building a tag detail page, hoping to display all documents under the tag and support pagination.

{# 页面标题可以显示当前标签的名称 #}
<h1>标签:{% tagDetail with name="Title" %}</h1>
<p>描述:{% tagDetail with name="Description" %}</p>

<div class="document-list">
    {# 使用tagDataList标签,type="page"开启分页功能 #}
    {% tagDataList archives with type="page" limit="10" %}
        {% for item in archives %}
        <div class="document-item">
            <a href="{{item.Link}}">
                {% if item.Thumb %}
                <img src="{{item.Thumb}}" alt="{{item.Title}}" class="document-thumbnail">
                {% endif %}
                <h2 class="document-title">{{item.Title}}</h2>
            </a>
            <p class="document-description">{{item.Description}}</p>
            <div class="document-meta">
                {# 获取文档所属分类的标题 #}
                <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                {# 格式化文档发布时间 #}
                <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </div>
        </div>
        {% empty %}
        <p>该标签下没有任何文档。</p>
        {% endfor %}
    {% endtagDataList %}

    {# 引入分页导航 #}
    <div class="pagination-container">
        {% pagination pages with show="5" %}
            <ul>
                <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>
        {% endpagination %}
    </div>
</div>

In this example,tagDataListAutomatically retrieve the current tag pagetagIdand display the documents in the form of 10 per page.paginationThe tag is responsible for rendering the complete pagination navigation. Throughitem.CategoryIdandcategoryDetailThe combination of labels, we can also display the name of the category to which each document belongs in the document list.

Example two: Display the latest documents under the specified tag in the sidebar.

If you want to display the latest 5 documents under a specific tag in a fixed area of the website, such as the sidebar, you can do this:

<div class="sidebar-block">
    <h3>“Go语言”标签下的最新文档</h3>
    <ul>
        {# 假设标签ID为10,获取最新5篇文档 #}
        {% tagDataList archives with tagId="10" order="id desc" limit="5" %}
            {% for item in archives %}
            <li>
                <a href="{{item.Link}}">{{item.Title}}</a>
                <span>({{stampToDate(item.CreatedTime, "01-02")}})</span>
            </li>
            {% empty %}
            <li>暂无相关文档。</li>
            {% endfor %}
        {% endtagDataList %}
    </ul>
</div>

This example shows how to specify explicitlytagIdandlimitParameters to achieve accurate content recommendation.

By flexible applicationtagDataListThe label and its parameters, you can create various forms of label document lists according to the actual needs of the website, greatly enrich the way you present content, and optimize the user's browsing experience.


Frequently Asked Questions (FAQ)

  • tagListandtagDataListWhat is the difference between two tags? tagListTags are mainly used to obtain the 'list of tags themselves', for example, you may want to display a cloud map of all popular tags at the bottom or in the sidebar of the website, or list all tag names on the tag homepage.It returns a series of tag objects (including tag ID, title, link, etc.). AndtagDataListThe tag is used to retrieve the document list under the specified tag, which is to say, according to one or more tags, find all the documents marked with these tags. In short,tagListThe focus is on the tag itself,tagDataListThe focus is on the document associated with the tag.

  • How to display the classification information of each document in the tag document list?Upon passingtagDataListWhen the tag loops through documents, eachitemAn object containsCategoryIda field, which is the ID of the document's category. You can combinecategoryDetailtags based on thisCategoryIdTo retrieve and display detailed information about the category, such as the category title or category link. The specific usage istagDataListUse within the loop,{% categoryDetail with name="Title" id=item.CategoryId %}To retrieve the category title.

  • Can I list multiple document lists under specified tags at the same time?According to the current template tag design of Anqi CMS,tagDataListlabel'stagIdThe parameter only supports specifying a single tag ID. If you need to list documents under multiple specific tags at the same time, it cannot be done directly through atagDataListImplement the call. Typically, you can use it multiple timestagDataListLabel, call for each label to be displayed once; or, if you have more complex aggregation requirements, you may need to develop a secondary development, perform complex query logic in the backend controller, and then pass the results to the frontend template for rendering.

Related articles

How to get and display the detailed information of a specified Tag label (name, description)?

As an operator of the AnQiCMS website deeply engaged in content operation, I fully understand the importance of tags in content organization and user experience.Tags can not only help readers quickly find the content they are interested in, but are also the key elements for optimizing website structure and improving SEO performance.Today, we will discuss in detail how to obtain and display the detailed information of the specified Tag label in AnQiCMS, including its name and description.

2025-11-06

How to display the custom parameter fields of an article on the article detail page?

As an experienced CMS website operation personnel of an enterprise, I know that the standard fields often cannot meet the growing personalized needs of the website.The introduction of custom parameter fields has provided us with great flexibility, allowing us to add various unique attributes to articles based on different content models, thereby enriching the content dimensions and enhancing user experience.This article will detail how to effectively display the custom parameter fields of an article on the AnQi CMS article detail page.

2025-11-06

How to implement lazy loading of images in article content?

Implementing the lazy loading of images in article content in AnQi CMS is a key link in improving website performance and user experience.As a website operator, I know full well the importance of loading speed for search engine rankings and user retention, and images, as an important part of web content, are often the main factors causing web pages to become bulky and slow to load.

2025-11-06

How to split a template into multiple reusable parts (such as header, footer)?

As a practitioner who is deeply familiar with the operation of AnQiCMS, I know that content quality and website efficiency are the core of attracting and retaining users.In daily operation, we must not only pay attention to the content itself, but also ensure the efficiency and maintainability of the website structure.The modular decomposition of templates is the key technology to achieve this goal. Aqie CMS provides a powerful and flexible template mechanism that allows us to easily decompose website templates into smaller, more manageable reusable parts, such as headers, footers, sidebars, etc.

2025-11-06

How to integrate a feedback form on a website and retrieve custom fields entered by the user?

As a senior CMS website operation personnel of an enterprise, I fully understand the importance of interacting with users, and the message form is the core channel for collecting user feedback and understanding user needs.The AnQi CMS was designed from the outset to fully consider the actual needs of enterprises and content operation teams, providing a simple yet powerful message management feature, especially support for custom fields, allowing us to flexibly obtain the required user information. ### Overview of AnqiCMS Message Form Functionality In today's digital environment, user interaction with websites is increasingly important.Whether it is consulting products or providing advice

2025-11-06

How to retrieve and display the comment list of an article, and support comment pagination functionality?

In Anqi CMS, efficiently managing and displaying article comments is an important aspect for enhancing user engagement and content interaction.As an expert familiar with Anqi CMS operation, I will elaborate in detail on how to retrieve and display the comment list of articles on the website, and support comment pagination features to ensure your content can attract and retain users. ### Enable Comment Function and Backend Preparation Before delving into frontend template development, make sure that your Anqi CMS backend has correctly configured the comment function.Generally, you can find the relevant settings in the "Content Comment Management" section of the "Function Management" section.

2025-11-06

How to perform basic arithmetic operations such as addition, subtraction, multiplication, and division in a template?

In the AnQiCMS content management system, the flexibility of the template is one of its core advantages, allowing website operators to dynamically display content according to specific needs.As an experienced AnQiCMS website operator, I am well aware of the need for basic arithmetic operations in templates, which is crucial for implementing functions such as price calculation, product quantity statistics, or dynamic adjustment of display data.AnQiCMS powerful Django template engine syntax, not only supports content display and logical judgment, but also provides an intuitive way to perform basic mathematical operations such as addition, subtraction, multiplication, and division

2025-11-06

How to configure URL static rules to optimize the search engine ranking of the website?

As an experienced CMS website operation personnel of an enterprise, I know that a clear and semantic URL structure is crucial for the website to rank well in search engines.The pseudo-static rule is one of the key tools to achieve this goal.AnQiCMS (AnQiCMS) was designed with SEO-friendliness in mind from the beginning, incorporating powerful pseudo-static functions that allow website operators to flexibly configure URLs, thereby optimizing search engine crawling and user experience.This article will discuss in detail how to configure URL rewrite rules in Anqi CMS

2025-11-06