In website operation, we often need to flexibly control the display of content.For example, you may want to display the latest articles on the homepage, but not include a specific category, such as "Internal Notice" or "Archived Content
The AanQi CMS provides very convenient and powerful functions to meet these needs. By skillfully using the template tags inarchiveListWe can easily exclude specific category content from the document list, making your website content more precise and orderly.
How to accurately control: How to exclude specific category content?
Anqi CMS'sarchiveListLabels are the core tools we call document lists in templates.It is feature-rich and can filter and sort documents based on multiple conditions.archiveListThe tag provides a very practical parameter -excludeCategoryId.
This parameter allows you to specify one or more category IDs to remove documents under these categories from the current list.
Actual operation example:
1. Exclude a single category
Assuming your website has a category named "Internal Announcements" with category ID 5. If you want to exclude the content of this category from all article lists, you canarchiveListLabel it like this:
{% archiveList archives with type="list" limit="10" excludeCategoryId="5" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}">{{item.Title}}</a>
{# 这里是其他文档信息,例如简介、发布时间等 #}
<div>{{item.Description}}</div>
<span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
</li>
{% empty %}
<li>
该列表没有任何内容
</li>
{% endfor %}
{% endarchiveList %}
In this code,excludeCategoryId="5"Tell the system to ignore articles with category ID 5 when fetching the article list.
2. Exclude multiple categories
If you need to exclude multiple categories, such as "Internal Announcement" with category ID 5 and "Expired Activities" with category ID 8, just separate these category IDs with commas:
{% archiveList archives with type="list" limit="10" excludeCategoryId="5,8" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}">{{item.Title}}</a>
{# 您的文档列表循环代码 #}
</li>
{% empty %}
<li>
该列表没有任何内容
</li>
{% endfor %}
{% endarchiveList %}
Through this method, you can flexibly combine the categories that need to be excluded to meet more complex display requirements.
3. Use in conjunction with other filtering conditions
excludeCategoryIdThe parameter can be used with otherarchiveListParameters are perfectly combined. For example, you may want to display articles under 'Product Updates' with category ID 10, but at the same time, you want to exclude the content of a subcategory 'Old Version Products' (assuming ID 12) under this category:
{# 假设您只想显示分类ID为10的“产品更新”下的文章,但排除其子分类“旧版本产品” (ID 12) #}
{% archiveList archives with type="list" categoryId="10" excludeCategoryId="12" limit="10" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}">{{item.Title}}</a>
{# 您的文档列表循环代码 #}
</li>
{% empty %}
<li>
该列表没有任何内容
</li>
{% endfor %}
{% endarchiveList %}
Thus, you have implemented the need to further refine the exclusion of certain subcategories under a specific parent category.
How to find the category ID?The category ID can be found on the "Content Management" -u003e "Document Category" page of the Anqi CMS backend.Each category will display its unique ID next to it, making it convenient for you to configure.
Practical scenarios and advanced skills:
- Maintain the freshness of the content:On the homepage's "Latest Articles" or "Hot Recommendations" section, you can exclude some categories that have not been updated for a long time or have become outdated, ensuring that the content displayed to users is always the latest and most relevant.
- Optimize user experience:Under the website navigation menu, in the content preview or related recommendation modules, exclude categories such as internal management and copyright statements that are not suitable for direct display to ordinary users, making the content stream more focused.
- SEO strategy:In order to avoid certain low-quality or repetitive content from affecting the overall SEO weight of the website,
excludeCategoryIdExclude pages under these categories from the core content list to better focus on optimizing important content. - Content aggregation under multi-site management:If you have used the multi-site management feature of Anqi CMS and wish to aggregate content from other sites on one site while excluding certain categories,
excludeCategoryIdIt can also help you more accurately control the source of content.
By using flexibilityexcludeCategoryIdThis parameter allows you to have more precise control over the display logic of website content, enhancing the user experience and operational efficiency of the website.
Common Questions (FAQ)
1.excludeCategoryIdCan only exclude the top-level category?
No,excludeCategoryIdParameters can exclude any level of classification.If you provide the accurate ID of the category, whether it is a top-level category or a multi-level subcategory, the system will exclude the documents under it from the list.
2. If I exclude a parent category, will its child categories still be displayed?
excludeCategoryIdThe parameter is for excluding the specific category ID you have specified. If you exclude a parent category but do not exclude its subcategories, documents directly associated with the parent category will be excluded, but documents under the subcategory will still be excluded based on other conditions (such ascategoryIdThe parameter is displayed if it is specified (for parent category). To exclude the parent category and all its child categories, you need to list all the IDs of the relevant categories.excludeCategoryId.
3. I want to exclude documents of a specific subcategory under the current category on a category page, how can I do that?
On the category list page,archiveListLabels are usually automatically obtained to display the current category's ID. In this case, you can specify nothingcategoryIdparameters (for the system to automatically identify the current category), and thenexcludeCategoryIdParameter explicitly specifies the subcategory ID you want to exclude. As a result, the document list on the current category page will not include the content of that excluded subcategory.