When managing website content in AnQi CMS, we often need to precisely control the display of articles.Sometimes, we may want certain categories of articles not to appear in the regular article list, such as for internal notifications, test content, or some promotional information displayed only on specific pages.AnQi CMS provides a simple and efficient method to meet this kind of demand, allowing you to flexibly exclude specific categories or multiple categories of articles, thereby achieving more accurate content presentation.
Core solution: Flexible applicationarchiveListTag
In the template design of AnQi CMS,archiveListTags are the core tools we use to call up the article list. It is powerful, capable of filtering, sorting, and displaying articles based on various conditions. To achieve the purpose of excluding articles of specific categories,archiveListthe label provides a namedexcludeCategoryIdThe parameter is used specifically to specify the article categories that should not be displayed.
1. Exclude a single category of articles
If you only want to exclude a single category of articles, just inarchiveListSet in the labelexcludeCategoryIdParameter, and specify the unique ID of the category. For example, if you have an ID of5category, the articles under which you do not want to appear in the current list, you can write the code like this:
{% archiveList archives with excludeCategoryId="5" limit="10" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}"><h5>{{item.Title}}</h5></a>
<p>{{item.Description}}</p>
</li>
{% empty %}
<li>当前没有文章可显示。</li>
{% endfor %}
{% endarchiveList %}
This code will filter out the latest 10 articles from all articles but will skip all articles belonging to category ID of5's article.
2. Exclude articles from multiple categories
If you need to exclude articles from multiple categories at the same time,excludeCategoryIdthe parameter can also handle it. You just need to separate all the category IDs to be excluded with English commas,and you can. For example, to exclude ID5/8and12Category articles, you can operate like this:
{% archiveList archives with excludeCategoryId="5,8,12" limit="10" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}"><h5>{{item.Title}}</h5></a>
<p>{{item.Description}}</p>
</li>
{% empty %}
<li>当前没有文章可显示。</li>
{% endfor %}
{% endarchiveList %}
Through this method, you can exclude any number of categories you don't want to display in a tag.archiveListIn a tag, you can easily exclude any categories you don't want to display.
How to find the category ID?
To useexcludeCategoryIdParameter, you first need to know the unique ID of the category you want to exclude.This is very simple, you can log in to the Anqi CMS backend and go to the 'Content Management'-'Document Classification' page.In the category list, each category entry will clearly display its unique ID. Usually, you can also find this ID in the browser address bar when editing categories (for example: .../category/edit/10.10It is the category ID, or you can directly view the 'ID' column in the category list.
Combined with otherarchiveListParameters
excludeCategoryIdCan be used witharchiveListThe other parameters of the tag perfectly combine to make your article list display more accurate and flexible. For example, you may want to display all the latest articles except for specific categories and implement pagination:
{% archiveList archives with excludeCategoryId="5,8" type="page" limit="15" order="created_time desc" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}"><h5>{{item.Title}}</h5></a>
<p>发布时间: {{stampToDate(item.CreatedTime, "2006-01-02")}}</p>
</li>
{% endfor %}
{% endarchiveList %}
{# 添加分页功能 #}
{% pagination pages with show="5" %}
<ul>
{% if pages.PrevPage %}<li class="prev"><a href="{{pages.PrevPage.Link}}">上一页</a></li>{% endif %}
{% for item in pages.Pages %}<li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>{% endfor %}
{% if pages.NextPage %}<li class="next"><a href="{{pages.NextPage.Link}}">下一页</a></li>{% endif %}
</ul>
{% endpagination %}
This code will display all articles except for those with category ID of5and8, sorted by creation time in descending order, showing 15 articles per page, and supporting pagination.
Extended application: Exclude articles with specific recommended attributes
In addition to excluding articles by category, AnQi CMS also provides a feature to exclude articles by 'Recommended Properties (Flag)'. If your article is marked with specific properties (such as: 头条[h]/推荐[c]/幻灯[f]Etc.), you can also useexcludeFlagParameters to avoid these articles from appearing in the list. For example, to exclude all articles marked with the "recommended" attribute:
{% archiveList archives with excludeFlag="c" limit="10" %}
{# 文章列表内容 #}
{% endarchiveList %}
Summary
ByarchiveListlabel'sexcludeCategoryIdParameters, Anqi CMS provides great flexibility for website operators, allowing them to precisely control the display range of articles according to actual needs.Whether it is to exclude a single rarely used category or filter out multiple categories containing specific content, this feature makes content management more efficient and convenient, ensuring that your website content is presented to visitors in the most reasonable and expected form.
Frequently Asked Questions (FAQ)
Q1: How can I display articles under a certain main category while excluding specific subcategory articles?
A1: You can specify the ID of the main category tocategoryIdthe parameter, and then specify the ID of the sub-category toexcludeCategoryIdParameters. For example, if you want to display the category ID of10exclude the articles under the sub-category ID15The article can be written like this:{% archiveList archives with categoryId="10" excludeCategoryId="15" %}In addition, if you only want to display categories10You can use to display articles under a category without including any subcategory articleschild=falseparameters:{% archiveList archives with categoryId="10" child=false %}.
Q2: I have setexcludeCategoryIdBut found that the article was not excluded normally, what could be the reason?
A2: First, please checkexcludeCategoryIdAre the classification IDs entered in the parameters correct and free of errors, and are commas used between multiple IDs in English?,Next, confirm that your template code has been used correctly.archiveListtags as wellexcludeCategoryIdThe parameter does not have other more specific filtering conditions (for example, specifying directlycategoryIdThe excluded category) overrides this exclusion rule. Finally, clear the website cache (if enabled) to ensure that the latest template code and data are effective.
Q3:excludeCategoryIdDoes the parameter affect the total number of articles counted?
A3: Yes,excludeCategoryIdThe parameter will directly exclude articles of specified categories from the total number of articles that meet the conditions when filtering articles. Therefore, if you are usingarchiveListWhen combined with pagination, excluding articles will reduce the total number of pages and total entries, as they are based on the actual number of displayed articles.