During website operation, we often need to fine-tune and display the content.For example, we may wish to not display certain internal announcements, specific promotional content, or some drafts that are not suitable for external display when recommending articles on the homepage.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers such needs and provides a simple and flexible way to achieve this - by specifying exclusion parameters in the document list tag.
This article will delve into how to exclude certain categories of articles from the document list in AnQiCMS, helping you control content display more effectively and optimize the user experience.
精准控制:在AnQiCMS文档列表中排除特定分类文章
One of the core advantages of Anqi CMS lies in its flexible content management and template tag system. When you need to display a list of articles on the front-end page of the website, you usually usearchiveListThis powerful template tag. It can not only help you filter specific category articles and sort them by various conditions, but also easily implement the exclusion of article categories.
core tools:excludeCategoryIdParameters
To implement the classification exclusion of document lists, AnQiCMS provides a very intuitive and powerful parameter: EnglishexcludeCategoryId. As the name implies, this parameter allows you to specify one or more unique category IDs, so that articles under these categories will not appear in the current document list.
How to find the category ID?
In the Anqi CMS backend, you can easily find the unique ID of each category.
- Login to your AnQiCMS backend.
- Navigate to 'Content Management' -> 'Document Categories'.
- In the category list, each category entry will display an "ID" column.This is the category ID you need to use.
.../category/edit?id=10Here, the number 10 is the category ID
How to use in templateexcludeCategoryId?
Once you have determined the category ID to exclude, you can apply it to your template filearchiveListtags.
Basic usage: Exclude a single category
Assuming you want to exclude all articles under the category of "Internal Notice" in an article list with ID of10. YourarchiveListtag can be written as:
{% archiveList archives with type="page" limit="10" excludeCategoryId="10" %}
{# 在这里循环显示您的文章内容 #}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
<p>{{item.Description}}</p>
<span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
</a>
</li>
{% empty %}
<li>当前没有可显示的文章。</li>
{% endfor %}
{% endarchiveList %}
Advanced usage: exclude multiple categories
If you need to exclude multiple categories at the same time, for example, ID of10the 'Internal Announcement' and ID of12the 'Draft' category, you just need to separate these category IDs with commas:
{% archiveList archives with type="page" limit="10" excludeCategoryId="10,12" %}
{# 在这里循环显示您的文章内容 #}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
<p>{{item.Description}}</p>
<span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
</a>
</li>
{% empty %}
<li>当前没有可显示的文章。</li>
{% endfor %}
{% endarchiveList %}
excludeCategoryIdWithcategoryIdto be used together
excludeCategoryIdParameters can be withcategoryIdParameters are used together to achieve more refined filtering. For example, you may only want to display in the "News Center" (assuming ID is1)下显示文章,但同时要排除“新闻中心”内的“行业活动”(假设ID为5)这个子分类的文章。
In this case,categoryIdauto will first filter out all articles under "News Center" and its subcategories (ifchildthe parameter is true, the default is true), thenexcludeCategoryIdexclude the articles with category ID of5.
{% archiveList newsArticles with type="page" categoryId="1" excludeCategoryId="5" limit="10" %}
{# 显示属于分类ID 1,但不属于分类ID 5 的文章 #}
{% for item in newsArticles %}
<li>...</li>
{% empty %}
<li>没有找到符合条件的新闻文章。</li>
{% endfor %}
{% endarchiveList %}
Practical suggestions and precautions.
- Clearly classified ID:Before modifying the template, please ensure that the category ID you want to exclude is accurate. An incorrect ID may lead to unexpected results.
- Content existence:Please note,
excludeCategoryIdJust control the contentFront-end display, not delete the content. The excluded articles still exist in your AnQiCMS system and can be accessed via their direct URL. - Multiple applications:If your website displays article lists in multiple places (such as the homepage, sidebar, specific专题 pages, etc.) and you want to apply the same exclusion logic in all these places, you need to set it in each relevant
archiveListLabels are added in all tagsexcludeCategoryIdParameter. - SEO considerations:If the excluded category articles are the ones you don't want to be indexed by search engines, just
excludeCategoryIdIt is not enough to hide on the front end. You may need to combine the AnQiCMS Robots.txt configuration or the article detail page'snoindexsettings to prevent search engines from indexing.
By masteringexcludeCategoryIdParameters, you can manage the content presentation on AnQiCMS website more flexibly and accurately, ensuring that visitors always see the article list that best fits your operational strategy.
Common Questions and Answers (FAQ)
Q1:excludeCategoryIdDoes the parameter affect the SEO performance of the article?
A1:excludeCategoryIdIt mainly controls the article in a specific listFront-end display。文章本身如果仍然有可访问的URL链接,并且没有通过Robots.txt或Englishnoindex标签等SEO手段进行阻止,搜索引擎依然可以抓取并收录这些文章。如果您不希望某个分类的文章被搜索引擎收录,建议在后台“文档分类”编辑页面或单个文章编辑页面中,通过高级SEO设置来添加noindexLabel, or configure it in the Robots.txt management of AnQiCMS.
Q2: If I exclude a parent category, will all the subcategory articles under it also be automatically excluded?
A2:excludeCategoryIdThe parameter directly affects the category ID associated with the article.If you exclude an ID of a parent category (for example, ID 10), then the articles directly under ID 10 will be excluded.CategoryIdIs the ID of a subcategory (for example, if the ID is 11, it is a subcategory of ID 10), unless you also specify ID 11 explicitly,excludeCategoryIdin the middle, otherwise these subcategory articlesWould not be automatically excluded. To ensure the exclusion of the entire category tree, you may need to manually list all related parent and child category IDs.
Q3: BesidesexcludeCategoryIdWhat are some parameters that can help me filter the article list more precisely?
A3: AnQiCMS'sarchiveListTags provide various powerful filtering parameters:
categoryId: 指定要包含的分类ID(支持多个ID用逗号分隔)。moduleId: 根据文章