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";Or in a product list, you want to exclude those categories that are 'discontinued' or 'internal testing' to keep the user interface simple and clear.
Safe CMS provides very convenient and powerful features to meet such needs. By skillfully using template tags in thearchiveListWe can easily exclude specific categories of content in the document list, making your website content more accurate and organized.
Precise control: How to exclude specific category content?
Of Security CMSarchiveListThe tag is the core tool we use to call the document list in the template.It is feature-rich and can filter and sort documents based on various conditions.When we want to exclude a specific category from a document list,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 Announcement" with category ID 5. You want to exclude the content of this category from all article lists, then you canarchiveListUse this label:
{% 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 block,excludeCategoryId="5"Tell the system to ignore articles with category ID 5 when retrieving the list of articles.
2. Exclude multiple categories
If you need to exclude multiple categories, such as the category ID 5 'Internal Announcement' and category ID 8 'Expired Activities', 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 %}
By this means, you can flexibly combine the categories that need to be excluded to meet more complex display requirements.
3. Use with other filtering conditions.
excludeCategoryIdThe parameter can be used with otherarchiveListParameters perfectly combined. For example, you may only want to display articles under the 'Product Update' category with ID 10, but at the same time, you want to exclude the content of a subcategory 'Old Version Product' (assuming ID 12):
{# 假设您只想显示分类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 achieved the need to further refine and exclude certain subcategories under a specific parent category.
How to find the category ID?The category ID can be found on the 'Content Management' -> 'Document Category' page in 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:
- Keep the content fresh:On the homepage of the website, in the 'Latest Articles' or 'Hot Recommendations' area, you can exclude some categories that have not been updated for a long time or are outdated, ensuring that the content shown to users is always the latest and most relevant.
- Optimizing user experience: Under the website navigation menu, in the content preview or related recommendation module, 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:Sometimes to avoid certain low-quality or repetitive content from affecting the overall SEO weight of the website, it can be done by
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 multiple site management feature of AnQi CMS and want to aggregate the content of other sites on one site, while excluding certain specific categories,
excludeCategoryIdIt can also help you control the source of content more accurately.
By flexible applicationexcludeCategoryIdThis parameter allows you to finely control the display logic of website content, improving the user experience and operational efficiency of the website.
Frequently Asked Questions (FAQ)
1.excludeCategoryIdCan I exclude the top-level category only?
No,excludeCategoryIdParameters can exclude any level of categorization. As long as 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 subcategories still be displayed?
excludeCategoryIdThe parameter is for excluding the explicitly specified category ID. If you exclude a parent category but do not exclude its subcategories, then the documents directly associated with the parent category will be excluded, but the documents under the subcategory will still be based on other conditions such ascategoryIdIf the parameter is specified, the parent category) is displayed. To exclude the parent category and all its subcategories, you need to list all relevant category IDs.excludeCategoryId.
3. I want to exclude a specific subcategory of documents under the current category on a category page, how do I operate?
On the category list page,archiveListTags usually automatically obtain the ID of the current category to display the content. In this case, you can specifycategoryIdparameters (for the system to automatically identify the current category), and then go throughexcludeCategoryIdThe parameter 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.