How to display documents under the current category using the `categoryList` tag without including documents from subcategories?

Calendar 👁️ 61

When building a website with AnQi CMS, we often encounter the following requirements: On a category page, we want to display only the documents that belong to the current category and not mix in the content of the documents from its subcategories.This is particularly important in scenarios where the content structure is clear and redundant information is avoided.Today, let's delve into how to accurately achieve this goal through the template tags of Anqi CMS.

Understanding the relationship between AnQiCMS categories and documents

AnQi CMS was designed with flexibility in content hierarchy from the outset.Categories can have subcategories, and documents can belong to any category.By default, for the convenience of content aggregation display, the document list tag will usually automatically include the content of the subcategories when called.This design provides convenience in some scenarios, but in some cases where it is necessary to strictly differentiate between hierarchical content, we need to perform refined control.

Core strategy:archiveListlabel'schildParameter

To achieve the goal of displaying only the documents under the current category and not including the documents of subcategories, we need to focus on the core isarchiveListThe tag is specifically used to retrieve document lists, it provides a parameter namedchildwhich is the key to controlling this behavior.

childThe parameter supportstrueandfalsetwo values:

  • child=true(default value)This indicates that when querying documents, it will not only include the documents under the currently specified category but will also recursively include all subcategories (including the subcategories of subcategories, and so on) within these subcategories.
  • child=falseThis indicates that when querying documents, it will strictly limit to the current specified category and will not retrieve any documents from its child categories.

Therefore, our solution is to usearchiveListWhen labeling, set it clearlychild=false.

Let's understand through a specific example. Suppose you are designing a category page template, and you want to list only the articles under the current category on this page.

{# 假设这是分类页面模板,我们首先需要获取当前分类的ID和标题 #}
{% categoryDetail currentCategory with name="Id" %} {# 获取当前分类的ID,并赋值给 currentCategory 变量 #}
{% categoryDetail categoryTitle with name="Title" %} {# 获取当前分类的标题,并赋值给 categoryTitle 变量 #}

<div class="category-header">
    <h1>{{categoryTitle}}</h1>
    <p>以下是“{{categoryTitle}}”分类下的所有文档(不含子分类)。</p>
</div>

<div class="document-list">
    {# 使用 archiveList 标签,并设置 categoryId 为当前分类ID,child=false 确保不包含子分类文档 #}
    {% archiveList archives with type="page" categoryId=currentCategory child=false limit="10" %}
        {% for item in archives %}
            <div class="document-item">
                <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
                <p>{{item.Description}}</p>
                <small>发布于: {{stampToDate(item.CreatedTime, "2006-01-02")}} | 浏览量: {{item.Views}}</small>
            </div>
        {% empty %}
            <p>抱歉,当前分类({{categoryTitle}})下没有找到文档。</p>
        {% endfor %}

        {# 如果需要分页,可以在此处添加分页标签 #}
        {% pagination pages with show="5" %}
            <div class="pagination-controls">
                {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
                {% for p in pages.Pages %}<a href="{{p.Link}}" class="{% if p.IsCurrent %}active{% endif %}">{{p.Name}}</a>{% endfor %}
                {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
            </div>
        {% endpagination %}
    {% endarchiveList %}
</div>

In this example:

  • We first usecategoryDetailThe tag fetched the category ID of the current page (currentCategory) and the title (categoryTitle)
  • Next, inarchiveListIn the tag, we willcategoryIdthe parameter tocurrentCategory, to ensure the document query is limited to the current category.
  • The most critical step is to setchild=falseThis parameter tells AnQi

Related articles

How to build a multi-level category navigation in Anqi CMS template and judge whether each category has subcategories?

In today's increasingly rich website content, a clear and efficient navigation system is crucial for improving user experience and search engine optimization (SEO).Especially for websites with a large amount of content or multiple product categories, multi-level category navigation can help users quickly find the information they need while also showing the structural hierarchy of the website to search engines.Anqi CMS with its flexible and powerful template engine makes it simple and intuitive to build such a navigation.This article will deeply explore how to cleverly construct a multi-level classification navigation in Anqi CMS template, and intelligently judge whether each category contains subcategories

2025-11-08

How to retrieve and display custom document parameters for a specific named using the `archiveParams` tag?

In AnQi CMS, content management is not limited to preset fields such as titles, content, etc., but can also be enriched and expanded by custom parameters.When you set unique custom fields for articles, products, or other content models, how to accurately obtain and display these specific parameter names in the front-end template is a common requirement in template creation.This article will deeply explore how to flexibly obtain and display the custom parameters of the `archiveParams` tag.### Custom parameter setting

2025-11-08

How to retrieve all custom parameters of a document in an Anqi CMS template and display them in a fixed order?

In website content management, we often need to define unique attributes for different types of information to meet the diverse display needs of the website.The AnQi CMS provides powerful custom parameter functionality, allowing you to flexibly add additional information to documents (articles, products, etc.)When you want to obtain these custom parameters in the website front-end template and display them in the fixed order set in the background, the built-in template tags of Anqi CMS can well help you achieve this.

2025-11-08

How to combine the `archiveList` tag with query parameters in the URL to implement dynamic search and filtering?

Build an interactive and easy-to-navigate website on Anqi CMS, with dynamic search and filtering functions being indispensable.`archiveList` tag as the core tool for content output, cleverly combines URL query parameters, and can help us implement a powerful content discovery mechanism, allowing users to easily locate the information they are interested in. ### The core function of the `archiveList` tag The `archiveList` tag is used in AnQi CMS to retrieve and display document lists.

2025-11-08

How to use the `navList` tag to create a navigation bar with submenus in the Anqi CMS template?

In AnQi CMS template development, building a functional and user-friendly navigation bar is one of the core tasks of website frontend development.Especially when navigation needs to include multi-level sub-menus, the `navList` tag provided by Anqi CMS can help us efficiently meet this requirement.Understanding the core role of the `navList` tag The `navList` tag is a tool specifically used in the Anqi CMS template to retrieve website navigation data and display it on the page.

2025-11-08

How to determine if the current navigation item is the current page in the `navList` loop?

In website operation, a clear navigation structure is crucial for improving user experience.A good navigation not only helps visitors quickly find the information they need, but also guides users through visual cues (such as highlighting the current page) so that they always know where they are.In AnQi CMS, implementing this feature is quite intuitive and efficient, which is due to its powerful template tag system.

2025-11-08

How to dynamically generate a custom field comment form with `guestbook` tag and adapt to different input types?

Managing website comments in Anqi CMS is a common requirement in daily operations, especially when we need to collect specific information, a flexible and customizable comment form becomes particularly important.Aqie CMS fully considers this requirement and provides a powerful `guestbook` tag, allowing us to easily dynamically generate a feedback form with custom fields and adapt to various input types.The power of the `guestbook` form label The core lies in the `guestbook` tag

2025-11-08

How to display a document's comment list in Anqi CMS template, including reply and pagination features?

In Anqi CMS, add a comment list to the document content and enable it to have reply and pagination functions, which can greatly enhance the user interaction of the website.Users can express their opinions and discuss specific documents, which not only enriches the content ecosystem but also brings more vitality to the website. ### One: Displaying Comment Lists: The Foundation of Interaction To display comments on a document page, it mainly relies on the `commentList` tag built into Anqin CMS.This tag helps us easily get the comment data associated with the current document. First

2025-11-08