As a senior website operation expert, I know that AnQiCMS is powerful and flexible in content management.In daily content operations, we often need to control the displayed content in a refined manner. Tags (Tag) as an important dimension of content organization, the flexibility of their calling method is crucial.Today, let's delve into a frequently asked question: AnQiCMS'stagDataListDoes the tag support excluding specificmoduleIddocuments?

RevelationtagDataList: Does AnQiCMS support filtering bymoduleIddocuments?

AnQiCMS with its efficient and flexible content management capabilities is loved by a large number of webmasters and operators.tagDataListAs one of its powerful template tags, it is mainly used fortagIdGet the associated document list, which greatly facilitates the construction of tag-based aggregation pages or recommended content. However, in utilizingtagDataListWhen displaying content tags, many users may encounter a problem: does it support the direct exclusion of specificmoduleId(Model ID) documentation? Simply put, currentlytagDataListthe design of tags,Not provided directlyexcludeModuleIdThis parameter is used to exclude documents with specific model IDs.

Let's review firsttagDataListThe core functions and supported parameters of the tag. According to the official documentation of AnQiCMS,tagDataListThe tag is mainly used to retrieve the document list under a specified Tag, it supports the following key parameters:

  • tagId: Specify the Tag ID, which is the most core parameter.
  • moduleId: This parameter can help usincludeDocuments from a specific document model. For example, setmoduleId="1"You can only retrieve article model documents associated with the tag
  • order: Specify the sorting rules of the document.
  • limit: Control the number of documents displayed.
  • type: Define the list type, such as pagination (page) or a regular list (list)
  • siteId: If it is a multi-site mode, you can specify the site ID.

From these parameters we can clearly see,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", andtagDataListOnly the option to select the 'Article Model' is provided, without a direct path to 'Not select the Product Model'.

This is similar to some other list labels in AnQiCMS, such asarchiveListprovided byexcludeCategoryId(Exclude Category ID) Parameter for comparison,archiveListCan flexibly exclude specific category content, but even inarchiveListthere is no directexcludeModuleIdThe parameter indicates that AnQiCMS, in its design, may be more inclined to handle exclusion operations at the module level, or encourage more refined differentiation through content categorization.

flexible response: implementationmoduleIdexclusion strategy

AlthoughtagDataListThere is no directexcludeModuleIdHowever, as a senior operator, we are always able to find flexible solutions. Here are several practical strategies that can help you achieve specific features in AnQiCMS.moduleIdDocument exclusion:

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

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

  • Implementation steps:

    1. UsetagDataListLabel normally retrieves all documents under the specified tag without specifyingmoduleIdparameters, or only specify the main set you want to includemoduleId.
    2. While traversing in a looparchives(or you define other variables) when using{% if %}Tag judgmentitem.ModuleIdIs the ID you want to exclude
    3. Ifitem.ModuleIdIf not equal to the excluded ID, the document content is displayed normally
  • Code example:Assuming you want to display the label ID of1document, but to excludemoduleIdWith2(assuming it is a product model) document.

    <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>
    
  • Advantage:Implementation is simple, no need to modify the core system code, high flexibility, can be combined with complex logic for judgment (such as excluding multiple at the same time)moduleIdor excluding specificmoduleIdbelow specificcategoryIddocument).

  • Shortcomings:In cases where the number of associated documents is very large and a high proportion of documents need to be excluded, it may first load more data into memory for filtering, 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 suggest that your content organization structure can be further optimized.

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