How to control the article list to only display documents under the current category and not include content from its subcategories?

Calendar 👁️ 57

When managing website content in Anqi CMS, we usually organize articles into different categories, forming a clear hierarchical structure.This structure provides great convenience when managing content in the background.However, when displaying the article list on the front-end page, we sometimes need to control the display range of the content more precisely, for example, we only want to display the articles directly published under the current category, and not include the content in the sub-categories.

Fortunately, AnQi CMS provides a simple and powerful solution: utilizingarchiveListtemplate tagschildParameter.

Understanding the problem: the need for default behavior and precise control

By default, when you are on a category page (for example, visiting the "News Center" category) usingarchiveListthe tag to call the article list, Anqi CMS will intelligently obtain the articles under the category ofand all its subcategoriesarticles. This is convenient in many scenarios because it can automatically aggregate related content.

But imagine such a situation: you have a "product introduction" category, under which there are subcategories such as "mobile phones", "computers", and "accessories."}On the "Product Introduction" page, you might only want to display some general, overview articles that belong directly to the "Product Introduction" category, rather than mixing all specific product articles under "Mobile", "Computer", and "Accessories" together.At this point, it is necessary to exclude articles from subcategories.

Solution:archiveListlabel'schild=falseParameter

Of Security CMSarchiveListTags are the core tools used to retrieve and display article lists in templates. They provide multiple parameters to finely control the filtering conditions of articles, among whichchildThe parameter is the key to solving our current problem.

childThe parameter supportstrueorfalsetwo values:

  • child=true(Default behavior): This will retrieve the articles under the specified category and all its subcategories. If you do not set this parameter, the system will default totrueProcess.
  • child=falseThis will only retrieve the specified category belowDirect publishof the article, completely excluding the content of any subcategories.

Therefore, to implement a document list that only displays documents under the current category and not the content of its subcategories, we need toarchiveListExplicitly specify in the tagcategoryIdthe parameter (i.e., the ID of the current category), and tochildthe parameter tofalse.

Implementation steps and code examples

Typically, you will be in a category list template file (such as/template/你的模板名/article/list.htmlor more specificarticle/list-{分类ID}.htmlUsed inarchiveListtags to display the article.

  1. Get the current category ID:In the context of the category page, Anqicms usually exposes the current category information to the template. You can{{category.Id}}to obtain the unique ID of the current category.

  2. UsearchiveListTags:Assign the obtained category ID toarchiveListofcategoryIdParameters, and you willchildthe parameter tofalse.

Below is a specific template code example showing how to display only the current category's articles on the article list page, without including the content of subcategories:

{# 假设这是在“文章”模型的某个分类列表模板中(例如:/template/default/article/list.html) #}

{# 1. 获取当前分类的ID。在分类页面上下文中,可以直接访问 'category.Id' #}
{% set currentCategoryId = category.Id %}

<div class="category-articles-section">
    {# 2. 显示当前分类的标题 #}
    <h1>{{ category.Title }} 下的最新文章</h1>
    <p>(只包含直接发布在本分类下的内容,不含子分类)</p>

    <ul>
        {# 3. 使用 archiveList 标签,指定当前分类ID,并设置 child=false #}
        {% archiveList archives with type="page" categoryId=currentCategoryId child=false limit="10" %}
            {% for item in archives %}
            <li>
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p>{{ item.Description }}</p>
                <small>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }} | 浏览量: {{ item.Views }}</small>
            </li>
            {% empty %}
            <li>
                当前分类下没有直接发布的文章。
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>

    {# 4. 如果需要分页,可以继续添加分页标签 #}
    <div class="pagination-area">
        {% pagination pages with show="5" %}
            {# 首页 #}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
            {# 上一页 #}
            {% if pages.PrevPage %}
            <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
            {% endif %}
            {# 中间多页 #}
            {% for item in pages.Pages %}
            <a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
            {% endfor %}
            {# 下一页 #}
            {% if pages.NextPage %}
            <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
            {% endif %}
            {# 尾页 #}
            <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        {% endpagination %}
    </div>
</div>

By the above code, you can precisely control the article list to only display the content under the current category without worrying about the mixing of articles in subcategories.This approach helps create a clearer and more user expectations conforming content display page, improving the overall website user experience and content management efficiency.


Frequently Asked Questions (FAQ)

Q1: Why did my article list show subcategory content even though I did not explicitly set itchildthe parameter?A1:archiveListin the labelchildThe default parameter value istrue. This means if you do not explicitly setchild=falseThe system will automatically include the current category and all subcategories under it. To only display the content of the current category, be sure tochildthe parameter tofalse.

Q2: How to dynamically assign the ID of the current category in the template tocategoryIdthe parameter?A2: When handling the template of the category list page or category detail page, the information of the current category is usually loaded intocategorythe object. Therefore, you can use it directly.{{category.Id}}Get the current category ID and assign it toarchiveListlabel'scategoryIdParameter.

Q3: How should I set up to display all categories (including subcategories) articleschildthe parameter?A3: If you wantarchiveListThe label behavior is set to default, which means it displays articles of the current category and all its subcategories, you can choose not to set itchildparameter (because it is set totrue), or explicitly set it tochild=true. Both methods have the same effect. For example:{% archiveList archives with type="page" categoryId=currentCategoryId limit="10" %}or{% archiveList archives with type="page" categoryId=currentCategoryId child=true limit="10" %}.

Related articles

How to define a new field in a custom content model and flexibly call and display these fields on the front-end page?

In AnQi CMS, using a custom content model to manage and display personalized content is one of its core strengths.This allows us to flexibly create dedicated data structures for different types of content according to specific business requirements.This article will discuss in detail how to define these custom fields in the background, as well as how to cleverly call and display them on the frontend page. ### Define a new field in the backend content model The content model is like a "blueprint" for content, it determines what information each type of content (such as articles, products, cases, etc.) should include. To define a new field

2025-11-08

How can AnQi CMS display image watermarks or anti-crawling interference codes on the front end to protect original content?

In the current information explosion of the Internet environment, the value of original content is increasingly prominent.However, content plagiarism and malicious scraping have also become a major headache for many website operators, not only damaging the creators' labor results, but also possibly affecting the website's search engine rankings and brand reputation.Faced with this challenge, AnQiCMS (AnQiCMS) fully understands the importance of content protection, and is built-in with front-end image watermarking and anti-crawling interference code functions, aiming to provide a solid defense line for your original content.### Understand the necessity of content protection Before discussing specific features

2025-11-08

How to clearly display the user's input search keywords and related documents on the search results page?

In Anqi CMS, create a highly efficient and user-friendly search results page that can not only help visitors quickly find the information they need, but can also significantly improve the overall professionalism and conversion rate of the website.This article will delve into how to clearly display the search keywords and related documents entered by users under the powerful functions of AnQi CMS.Build a dedicated search page template: Clearly show user intent The template system of Anqi CMS is known for its high flexibility, allowing you to customize each page according to your business needs.The search results page usually corresponds to the current template directory under

2025-11-08

How to configure the pagination display of the article list and allow custom pagination links and styles?

In website operation, as the content volume grows, how to effectively organize and present these contents so that users can easily browse them is the key to improving user experience and website performance.The pagination display of the article list is an important means to achieve this goal.AnQiCMS provides a powerful and flexible template tag feature, allowing us to easily configure the pagination display of article lists and customize the link structure and visual style of pagination according to actual needs.### Configure the article list to enable pagination Enable pagination for the article list

2025-11-08

On the article detail page, how to obtain and display a list of recommended articles related to the current article?

In website content operation, improving user stay time and reducing bounce rate is the goal pursued by every operator.After a user reads an article, if they can immediately see other content that interests them, it will undoubtedly greatly enhance their engagement, thereby improving the overall interactivity and user experience of the website.While AnQiCMS (AnQiCMS) is a powerful content management system, it provides us with convenient tools to implement intelligent recommendations for article detail pages without complex development work.The list of recommended articles not only provides users with a deeper reading experience, but also guides them to browse more website content

2025-11-08

How to retrieve and display the global settings information of a website, such as the website name, Logo, and filing number in the template?

When building website templates in AnQiCMS, we often need to display some general information at the website level, such as the name of the website, Logo image, and legal filing number required by law.This information is usually managed in the background global settings to ensure consistency across the entire site and ease of maintenance.AnQiCMS has a powerful template tag system, especially the `system` tag, which makes it very intuitive and efficient to obtain and display these global settings in the template.### Understanding Global Settings and `system`

2025-11-08

How to obtain and display the contact information configured on the back-end, such as phone numbers, email addresses, WeChat QR codes, and other diversified information?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that excels in helping enterprises display their brand image and provide convenient communication channels.For any website, having clear and easily accessible contact information is crucial for building trust with users and promoting cooperation.AnQi CMS deeply understands this, providing a set of intuitive and powerful functions that allow you to easily manage and display various contact information such as phone numbers, email addresses, WeChat QR codes, etc.### Backend Configuration: Central Management Center for Contact Information In AnQi CMS

2025-11-08

How to use the article's `flag` attribute (such as 'Top Story', 'Recommendation') to filter and highlight specific content?

In AnQi CMS, efficiently managing and highlighting specific content is the key to website operation success.When the content of the website becomes increasingly rich, how to ensure that important information can quickly attract the attention of visitors and guide them to browse the core content, which has become a problem that every operator needs to think deeply about.The Anqi CMS provides a powerful "recommendation attribute" (flag) feature that allows you to easily filter and highlight specific content, thereby enhancing user experience and website operation effects.### Understanding the `flag` attribute of Anqi CMS The `flag` attribute, as the name suggests

2025-11-08