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 various business needs.The AnQiCMS (AnQiCMS) provides great convenience for content operation with its powerful content model and template system.Today, let's delve into a very practical scenario in actual operation: how to accurately filter documents of specific content models from a Tag document list in the Anqi CMS template.
flexibly handle content: Anqi CMS' 'model' and 'label'
In AnQi CMS, the core of content management lies in the two major functions of 'Content Model' and 'Tags'. Understanding them is the prerequisite for accurate filtering.
Content ModelIt is the basis for defining the structure of different types of content, as the name implies.Whether it is a common "articleAnQiCMS 项目优势.md提及的“允许用户根据业务需求自定义内容模型”)使得我们可以根据实际业务需求,为不同类型的内容创建专属的管理和展示结构。例如,默认的“文章模型”和“产品模型”(参考help-content-module.md),each has its characteristics.
whileLabel (Tag)It 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 classification.For example, a 'New Launch' Tag may be associated with 'Articles' introducing the new product and the 'Product' page of the new product.help-content-tag.mdAlso mentioned that "document tags are not categorized and do not differentiate between models, the same tag can be assigned to documents of different content models simultaneously.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 well-structured and rich in themes.But sometimes, we may wish to display only documents under specific models when showing content under a certain Tag, such as displaying only specific new products (product models) on a "New Launches" Tag page, rather than market analysis articles about new products (article models).tagDataListthe filtering ability of tags.
Core Decryption:tagDataListthe "model" filtering ability of tags.
In the template system of Anqi CMS, the core tag used to call the document list under Tag is{% tagDataList %}。According todesign-tag.mdandtag-/anqiapi-tag/149.htmlThe description, this tag provides various parameters to customize the display of the document. The key parameter to solving our problem is —moduleId.
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, by settingmoduleIdYou can also easily filter it out and only display the part you want.
Practice: Filter specific model documents
Now, let's look at an actual example to see how to use it in a templatemoduleIdPerform filtering.
Step 1: Determine the target model ID
Firstly, you need to know the ID corresponding to the "content model" you want to filter. You can find it in the Anqi CMS backend by following the following steps:
- Log in to the Anqi CMS backend.
- Navigate to:Content Management -u003e Content Model.
- Here, you will see all the content models created (including the default "Article model" and "Product model" as well as any custom models you create).Each model will have a corresponding ID.
- The ID of the article model is usually
1The ID of the product model is2. - Please remember the numeric ID corresponding to your target model, for example, if we assume that we need to filter by "product model", its ID is
2.
- The ID of the article model is usually
Step 2: Write the template code to filter
Suppose we are editing the Tag document list page (for exampletag/list.html) and we want to display all documents belonging to "Product Model" under the current Tag on this page.
We will usetagDataListthe label and addmoduleId="2"Specify the filter product model.
Current tag: {% tagDetail with name="Title" %}
{# Use 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="{%