As an experienced website operations expert, I am well aware of the powerful and flexible content management of AnQiCMS.In daily content operation, we often need to perform refined control over the displayed content. Tags (Tag) as an important dimension for content organization, the flexibility of their calling method is crucial.tagDataList标签是否支持排除特定moduleId的文档?

UnveilingtagDataList:AnQiCMS是否支持按moduleId排除文档?

AnQiCMS with its efficient and flexible content management capabilities is deeply loved by webmasters and operators.tagDataListAs one of its powerful template tags, it is mainly used fortagIdGet the document list associated with it, which greatly facilitates the construction of aggregate pages based on tags or recommended content. However, in usingtagDataListLabel display content, many users may encounter such a problem: does it support direct exclusion of specificmoduleId(Model ID) documentation? Simply put, currentlytagDataListthe design of labels,并未直接提供excludeModuleId这样的参数来排除特定模型ID的文档.

我们先来回顾一下tagDataList标签的核心功能与支持的参数。根据AnQiCMS的官方文档,tagDataListThe label is mainly used to obtain the document list under a specified Tag, it supports the following key parameters:

  • tagId: Specify the ID of the Tag, which is the most core parameter.
  • moduleId: This parameter helps usincludingfrom a specific document model. For example, settingmoduleId="1"you can only get the document model documents associated with this tag.
  • order: Specify the sorting rule of the document.
  • limit: 控制显示文档的数量。
  • type: 定义列表类型,如分页(page)或普通列表(list).
  • siteId: 如果是多站点模式,可指定站点ID。

We can clearly see these parameters from this.moduleIdThe function is to "include" or "filter out" documents with specific model IDs, rather than "exclude". This means that if you want the content under a certain tag not to display documents from the "Product Model" category, thentagDataListOnly the option of selecting "Article Model

This is consistent with some other list labels in AnQiCMS (such asarchiveListprovided byexcludeCategoryIdThe parameter forming comparison excludes the category ID,archiveListCan flexibly exclude specific category content, but even inarchiveListthere is no directexcludeModuleIdParameter.This indicates that AnQiCMS, in its design, may be more inclined to handle exclusion operations at the module level through template logic, or encourage more detailed distinction through content classification.

flexible response: to implementmoduleIdthe strategy of exclusion

AlthoughtagDataListThere is no directexcludeModuleId参数,but as a senior operator, we can always find flexible solutions. Here are several practical strategies that can help you achieve specific functionality in AnQiCMS.moduleIdThe exclusion of documents:

1. Use template logic for post-filtering (most commonly used and recommended)

This is the most direct and flexible method. You can intagDataListAfter obtaining all document data associated with the label, in the template'sforAdd conditional judgment within the loop to filter out unnecessary model ID documents.

  • Implementation steps:

    1. UsetagDataListLabel normal to get all documents under the specified label without specifyingmoduleIdParameter, or only specify the main set you want to includemoduleId.
    2. In the loop traversalarchivesWhen using (or you define other variable names),{% if %}Label judgmentitem.ModuleIdWhether it is the ID you want to exclude.
    3. Ifitem.ModuleIdIf it is not equal to the ID that needs to be excluded, the document content will be displayed normally.
  • Code example:Assuming you want to display the label ID of1exclude the documents ofmoduleIdresponse for2(assuming it is a product model) documents.

    <div class="tag-documents-list">
        {% tagDataList archives with type="page" tagId="1" limit="10" %}
            {% for item in archives %}
                {%- if item.ModuleId != 2 %} {# 排除 moduleId 为 2 的文档 #}
                    <div class="document-item">
                        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                        <p>{{ item.Description }}</p>
                        {# 更多文档详情... #}
                    </div>
                {%- endif %}
            {% empty %}
                <p>当前标签下没有可展示的文档。</p>
            {% endfor %}
        {% endtagDataList %}
    
    
        {# 如果需要分页,分页标签仍然可以正常使用 #}
        {% pagination pages with show="5" %}
            {# 分页代码,此处略 #}
        {% endpagination %}
    </div>
    
  • Advantages:Implementation simple, no need to modify the core system code, high flexibility, can be combined with complex logic for judgment (for example, excluding multiple at the same time)moduleId, or excluding specificmoduleIdspecificcategoryIddocument).

  • Disadvantages:For cases with a very large number of associated documents and a high proportion of documents to be excluded, it may first load more data into memory before filtering, which is theoretically less efficient than querying and filtering directly on the backend.But for most websites, this performance overhead can be ignored.

2. Adjust content operation strategy

From the perspective of content operation and website architecture, if the content under a certain tag always needs to exclude documents of a specific model, this may indicate that your content organization structure can be further optimized.

  • Consider refining tags:Can you create more specific tags to avoid this conflict?For example, if the "Promotion" tag is associated with both "Articles" and "Products
  • Utilize the classification model:The label itself is cross-model, while classification is bound to a specific model. If the content attribute naturally belongs to a certain model, it can make more use of classification.