How to exclude specific categories or multiple categories of articles from the document list?

Calendar 👁️ 63

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.

Related articles

How to filter and loop through the document list under a specific category based on the category ID?

It is crucial to organize and present content when building and operating a website.Especially when the content of a website becomes increasingly rich, how to enable visitors to quickly find the information they are interested in and clearly browse all articles under a specific theme has become a carefully designed problem.AnQiCMS (AnQiCMS) provides powerful and flexible content management capabilities, allowing us to easily achieve precise control and display of document lists.

2025-11-08

How to display the latest N articles or products on the homepage and implement pagination control?

## Asecurity CMS: The Practice of Efficiently Displaying the Latest Content on the Homepage and Implementing Pagination The homepage is an important entry point for visitors to understand the site content and obtain the latest information, it is crucial to clearly and effectively display the latest published articles or products.The AnQi CMS provides powerful and flexible template tags, which help us easily achieve this goal, and can also fine-tune content pagination to ensure a smooth user experience.

2025-11-08

How to output variables in a template and safely escape content to prevent XSS attacks?

In the process of managing and displaying website content, ensuring the security of user data is a crucial link.It is an issue that every website operator needs to pay attention to when the website needs to display user submitted content or data obtained from external sources, how to effectively prevent cross-site scripting (XSS) attacks.AnQiCMS (AnQiCMS) took this into full consideration from the very beginning, providing solid security guarantees for content output through its powerful template engine and flexible filter mechanism.### Cross-Site Scripting Attack

2025-11-08

How to output the current date and time in the AnQiCMS template and specify the format?

Displaying the date and time in the AnQiCMS template in a specific format is a common requirement in website content operations.Whether it is to display the publication time of articles, the deadline of events, or show the current year in the footer, accurate and beautiful time information can enhance the user experience.AnQiCMS provides simple and efficient template tags, allowing you to easily implement these features. Next, we will discuss in detail how to output the current date and time in the AnQiCMS template and specify the format you need.

2025-11-08

How to display articles under a specific category without including its subcategories?

In website content management, we often encounter such needs: we want to display articles under a specific category on a page, but we don't want to include the sub-category articles under that category to maintain the purity and focus of the content.For example, you may have a "Company News" category that includes subcategories such as "Enterprise Dynamics" and "Industry Information", but on the homepage, you only want to display the pure "Company News" without mixing in the content of all subcategories.

2025-11-08

How to filter and display a list of articles based on their recommended attributes (such as “Top Article”, “Recommended”)?

In Anqi CMS, efficient content management is one of the keys to website success.Article recommendation attribute, as an important link in the operation of content refinement, it can help us display website content more flexibly, guide users to pay attention to key information, and thus improve the activity and conversion rate of the website.This article will delve into how to filter and display article lists based on the recommended attributes of articles (such as "Headline

2025-11-08

How to display the article list according to the article views, publish time, or backend custom sorting?

In website operation, the way articles are displayed directly affects user experience and content access efficiency.A well-organized list of articles that can highlight key points, significantly improving user retention and information acquisition efficiency.AnQiCMS as a flexible content management system provides powerful article list display functions, not only can it flexibly filter content, but also can freely adjust the sorting method of articles according to your content strategy, making your website content more attractive.

2025-11-08

How to obtain and display the title, content, thumbnail, and other core information of an article on the article detail page?

When operating a website, the article detail page is the key entry point for users to understand the core value of the content.A well-designed, comprehensive article detail page that not only improves user experience but also effectively helps search engines understand the content of the page, thus optimizing the website's SEO performance.AnQiCMS (AnQiCMS) provides a powerful and flexible template tag system that allows you to easily obtain and present all the core information of the article.

2025-11-08