In managing website content in AnQi CMS, we often need to precisely control the display of articles.Sometimes, we might want certain categorized articles to not appear in the regular article list, such as for internal notifications, test content, or promotional information that is displayed only on specific pages.AnQi CMS provides a simple and efficient method to meet such needs, allowing you to flexibly exclude specific categories or multiple categories of articles, thereby achieving more accurate content presentation.

Core Solution: Flexible ApplicationarchiveListtags

In the template design of AnQi CMS,archiveListTags are the core tools we use to call up the article list. They are powerful, able to filter, sort, and display articles based on various conditions. To achieve the purpose of excluding articles from specific categories,archiveListtag provides a name ofexcludeCategoryIdThe parameter is used to specify the article categories that should not be displayed.

1. Exclude articles from a single category

If you only want to exclude articles from one category, just inarchiveListsetting in the labelexcludeCategoryIdParameter, and specify the unique ID of the category. For example, if you have a category with ID5category, and you do not want the articles under this category to appear in the current list, your code can be written 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 that belong to category ID of5.

2. Exclude articles from multiple categories

If you need to exclude multiple categories of articles at the same time,excludeCategoryIdthe parameter can also handle it. You just need to separate all the category IDs you want to exclude with English commas,,for example, to exclude ID as5/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 %}

By this method, you can do this in onearchiveListTag, easily excluding any number of categories you do not want to display.

How to find the category ID?

to useexcludeCategoryIdParameters, 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 Category' page.In the category list, each category entry will clearly display its unique ID..../category/edit/10,“ here is the10It is the category ID), or directly view the 'ID' column in the category list.

With otherarchiveListParameters combined

excludeCategoryIdCan be used witharchiveListThe other parameters of the tag perfectly combine, allowing your article list to display more accurately and flexibly. For example, you may want to display all the latest articles except for specific categories, and also 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, displaying 15 articles per page, and supporting pagination.

Expand 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 articles are marked with specific properties (such as:)头条[h]/推荐[c]/幻灯[f]and), you can also useexcludeFlagparameter to avoid these articles from appearing in the list. For example, to exclude all articles marked as "recommended":

{% archiveList archives with excludeFlag="c" limit="10" %}
    {# 文章列表内容 #}
{% endarchiveList %}

Summary

PassarchiveListTagsexcludeCategoryIdParameters, Anqi CMS provides great flexibility to website operators, allowing precise control over the display range of articles according to actual needs.Whether it is to exclude a single rarely used category or to 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.


Common Questions (FAQ)

Q1: How can I display articles under a certain main category while excluding articles from a specific subcategory?

You can specify the ID of the main category to exclude.categoryIdThen, specify the ID of the subcategory to exclude.excludeCategoryIdFor example, if you want to display categories with ID:10All articles of 【en】but excluding its subcategory IDs15articles, it can be written like this: 【en】{% archiveList archives with categoryId="10" excludeCategoryId="15" %}Additionally, if you only want to display the category 【en】10Articles under the category without including any subcategories, can usechild=falseParameters:{% archiveList archives with categoryId="10" child=false %}.

Q2: I setexcludeCategoryId, but found that the articles were not excluded normally, could be what reasons?

A2: Firstly, please checkexcludeCategoryIdAre the classification IDs filled in correctly in the parameters, and are commas used between multiple IDs in English?,Also, confirm that your template code is using correctly.archiveListTags as wellexcludeCategoryIdParameter, and there are no other more specific filtering conditions (such as specifying directlycategoryIdThis exclusion category is covered by this exclusion rule. Finally, clear the website cache (if enabled) to ensure that the latest template code and data take effect.

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 the pagination feature, excluding articles will reduce the total number of pages and total entries, as they are based on the actual number of displayed articles.