How to filter documents of specific models in the Tag document list of AnQiCMS template?

As an experienced website operations expert, I know that the flexibility of the Content Management System (CMS) is the key to improving operational efficiency and meeting diverse business needs.AnQiCMS (AnQiCMS) relies on its powerful content model and template system, providing great convenience for content operation.Today, let's delve deeply into a very practical scenario in actual operation: how to accurately filter documents of a specific content model from the Tag document list in AnQi CMS template.

Flexibly control content: AnQi CMS' 'Model' and 'Tag'

In Anqi CMS, the core of content management lies in the two major functions of "content model" and "tags." Understanding them is the premise for precise filtering.

Content modelAs the name implies, it is the basis for defining the structure of different types of content.Whether it is a common "article", or a "product" with attributes such as price and inventory, or other custom "events", "cases", and model, they all have their own unique fields.Flexible content model design of Anqi CMS (such asAnQiCMS 项目优势.mdThe 'Allow users to customize content models based on business requirements' mentioned enables us to create dedicated management and display structures for different types of content. For example, the default 'Article Model' and 'Product Model' (refer tohelp-content-module.mdEach has its own characteristics.

AndTagThis is a cross-model, cross-category content classification method.It allows us to associate documents with the same topic, keywords, or attributes without being limited by traditional hierarchical classifications.For example, a 'new product launch' tag may be associated with the 'article' introducing the new product, as well as the 'product' page of the new product.help-content-tag.mdIt also mentions that document tags are not categorized by type and model, the same tag can be used to mark documents of different content models at the same time.This flexibility is particularly important in content marketing and SEO strategies.

When these two powerful functions are combined, we can build a website content system that is both clear in structure and rich in theme.But sometimes, we may wish to display only documents under a specific model when displaying content under a certain Tag, such as only displaying specific new products (product model) on a 'New Products Launch' Tag page, rather than market analysis articles (article model) about new products.This is when it needs to be usedtagDataListThe filtering ability of the tag.

Core decryption:tagDataListThe 'model' filtering ability of the tag.

In the Anqi CMS template system, the core tag used to call the document list under Tag is{% tagDataList %}. According todesign-tag.mdandtag-/anqiapi-tag/149.htmlThis label provides various parameters to customize the document display style. The key parameter for solving our problem ismoduleId.

moduleIdThe parameter allows you to specify the specific content model ID to retrieve the document list. This means that even if a Tag is associated with documents under multiple content models, you can setmoduleIdYou can also easily filter it out and only display the part you want.

Practice exercise: Filter specific model documents

Now, let's look at a real example to see how to use it in a templatemoduleIdfor filtering.

Step 1: Determine the target model ID

Firstly, you need to know the ID of the 'content model' you want to filter. You can find it by following these steps in the Anqi CMS backend:

  1. Log in to the AnQi CMS background.
  2. Navigate toContent Management -> Content Model.
  3. Here, you will see all the content models created (including the system default 'Article Model' and 'Product Model', as well as any custom models you have created).Each model will have a corresponding ID.
    • Usually, the ID of the 'article model' is1The ID of the 'Product Model' is2.
    • Remember the numerical ID of the target model you are looking for, for example, we assume we want to filter the 'Product Model', whose ID is2.

Second step: Write template code for filtering

Suppose we are editing the Tag document list page (for exampletag/list.html),and hope to display all documents belonging to the "product model" under the current Tag on this page.

We will usetagDataListTag, and join.moduleId="2"To specify the filtering of product models.

”`twig {# First, get the details of the current Tag, which is usually available by default in the tag/list.html template #} {# If it's not tag/list.html, you may need to use the tagDetail tag to get the current TagID, for example, {% tagDetail currentTag with name=“Id” %} #}

Current tag: {% tagDetail with name="Title" %}

{# Use the tagDataList tag and explicitly specify moduleId as 2 (product model) #} {% tagDataList archives with type=“page” limit=“10” moduleId=“2” %}

{% for item in archives %}
    <div class="product-item">
        <a href="{{item.Link}}">
            {% if item.Thumb %}
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
            {% else %}
                <img src="{% system with name='TemplateUrl' %}/images/default-product.png" alt="默认产品图">
            {% endif %}
            <h3>{{item.Title}}</h3>
        </a>
        <p>{{item.Description|truncatechars:80}}</p>
        {# 假设产品模型有自定义字段“price”,可以通过 item.price 调用 #}
        {# 可以在这里进一步调用产品模型的特有字段,例如:{{item.price}} #}
        <span class="view-count">{{item.Views}} 浏览</span>
        <span class="publish-date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
    </div>
{% empty %}
    <p>当前标签下,产品模型没有任何相关文档。</p>
{% endfor %}

{# 如果 type="page",则需要配合分页标签显示分页 #}
{% pagination pages with show="5" %}
    <div class="pagination-nav">
        {% if pages.FirstPage %}<a href="{{pages.FirstPage.Link}}">首页</a>{% endif %}
        {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
        {% for page_item in pages.Pages %}
            <a class="{%