How to only display documents of the current category on the category list page and not include documents of subcategories?

Calendar 👁️ 62

When operating a website, we often encounter the need to display content, one common scenario is how to accurately control the display content on the category list page.Sometimes, we hope to display not only the documents under a main category page but also the documents under all its subcategories to provide more comprehensive information.However, in some cases, in order to maintain the purity of the page theme and the focus of the content, we may only want to strictly display the documents under the current category and not include any content from subcategories.

AnQi CMS is a flexible content management system that fully considers the diverse needs of users and provides a very simple and efficient way to handle this content display logic.

The core feature revelation:archiveListwith the tag andchildParameter

The key to displaying only the current category documents in the category list page of AnQi CMS without including subcategory documents is to usearchiveListtemplate tagschildParameter.

archiveListThe tag is the core tool of Anqi CMS used to retrieve document lists, it supports various parameters to filter, sort, and control the display of documents. Among them,childThe parameter is used to control whether to include subcategory documents.

By default,childThe value of the parameter istrueThis means that when you call the category list page,archiveListWhen a tag is used, it automatically includes the documents under the current category and all its subcategories. This design provides rich content display in most cases.

But if your goal is to precisely display only the current category of documents, then just inarchiveListput in the tag.childthe parameter tofalse. The system will intelligently filter out all documents of subcategories after receiving this command, retaining only the content directly associated with the current category.

Below is an example of using in the category list page.archiveListLabel, and ensure that only the simplified examples of the current category documents are displayed:

{# 假设这是你的分类列表页模板,例如 /template/default/article/list.html 或 /template/default/article/list-123.html #}

<div class="category-document-list">
    {% archiveList archives with type="page" limit="10" child="false" %}
        {% for item in archives %}
        <div class="document-item">
            <a href="{{item.Link}}" title="{{item.Title}}">
                <h3>{{item.Title}}</h3>
                <p>{{item.Description|truncatechars:100}}</p>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </a>
        </div>
        {% empty %}
        <p>当前分类下暂无文档。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 如果需要分页,可以结合 pagination 标签使用 #}
    {% pagination pages with show="5" %}
        {# 分页导航的代码,根据你的模板设计进行编写 #}
        {% if pages.TotalPages > 1 %}
            <div class="pagination-nav">
                <a href="{{pages.FirstPage.Link}}" class="{% if pages.FirstPage.IsCurrent %}active{% endif %}">{{pages.FirstPage.Name}}</a>
                {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</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}}">{{pages.NextPage.Name}}</a>{% endif %}
                <a href="{{pages.LastPage.Link}}" class="{% if pages.LastPage.IsCurrent %}active{% endif %}">{{pages.LastPage.Name}}</a>
            </div>
        {% endif %}
    {% endpagination %}
</div>

In this example,archiveListlabel'schild="false"The parameter ensures that only documents under the current category (such as, pages with category ID 10) are listed, while documents under any subcategory (such as, category IDs 11, 12, etc.) of the category are excluded.

It is worth mentioning that it is usually not necessary to specify extra when using it in the category list pagearchiveListwhencategoryIdParameter. Because AnQi CMS is smart enough, it will try to read the category ID of the current page by default to get the document.Of course, if you need to use it on other pages or want to specify a category ID more explicitly, you can also do socategoryId="你的分类ID"to achieve.

Why choose precise display? The considerations behind it

Adopting this strategy of displaying only the current category documents can bring various benefits:

  1. Enhance user experience and navigation clarity:When the user clicks on a category, they expect to see documents directly related to the theme of that category.If mixed with the content of subcategories, it may confuse users and reduce search efficiency.The precise display can make the page theme more clear, allowing users to find the information they need at a glance.
  2. Optimize SEO effect:For search engines, the concentration and relevance of page content are important factors in the ranking algorithm.A page that only contains documents of the current category, with a higher keyword density and thematic focus, which helps search engines better understand the content of the page, thereby improving the ranking of the category page in related search results.
  3. Simplify content management logic:For website operators, precise control over content display can make the content structure clearer, convenient for daily content publication, maintenance, and data analysis.
  4. Avoid content repetition and dilution:Under certain complex classification systems, if the content of the sub-classification is also displayed on the parent classification page, it may lead to a large amount of repeated content display, diluting the unique value of each page.

MorearchiveListParameter Matching Suggestions

In the settingchild="false"On this basis, you can also combine otherarchiveListParameters, further refine your content display:

  • moduleId="1"(Model ID):If your website has multiple content models (such as articles, products), you canmoduleIdspecify parameters to display documents under specific models only.
  • order="id desc"(Sorting method):Control the document sorting, such as by most recent release (id desc), most viewed (views desc), or custom sorting (sort desc)
  • limit="10"(display count):Control the number of documents displayed per page.
  • flag="c"(Recommended Attribute):Only display documents with specific recommended attributes (such as recommended[c], headline[h], etc.).

By flexibly using these parameters, you can build highly customized and powerful category list pages in Anqi CMS, whether it is to enhance user experience, optimize SEO, or simplify content management, you can handle it with ease.


Frequently Asked Questions (FAQ)

1. This setting (child="false") will affect other category pages on my website?No.child="false"The parameter only modifies your settingsarchiveListThe specific category list page template takes effect. If you do not add or modify this parameter in the template of other category list pages, they will continue to use the original content display logic (usually including subcategory documents by default).

2. Can I display documents from the current category and a specific subcategory at the same time, excluding other subcategories, is this possible?Yes. In this case, you can omitchild="false"Parameters. Instead, it is directly incategoryIdEnter the category ID you want to include in the parameter, including the current category ID and the specific subcategory ID you want to display, separated by English commas,For example: {% archiveList archives with categoryId="1,2,5" type="page" limit="10" %}.

3. If my category list page template does not havearchiveListWhat should I do with the tags?If your category list page template does not havearchiveListLabel, that means that the current page may not be properly configured to display the document list. You need to manually add it in the templatearchiveListLabel. First determine which content model you want to display (for example, the article model ID is 1), then configure it according to the above example, at least includingmoduleIdandtypefor example:{% archiveList archives with moduleId="1" type="page" limit="10" child="false" %}Of course, if you need pagination, remember to addpagination.

Related articles

How is the 'Multi-site Management' feature of AnQiCMS implemented to display different site content independently?

## Deeply analyze the "Multi-site Management" feature of AnQiCMS: How to ensure independent display of content?How to efficiently manage content when operating multiple websites or owning multiple brand sub-sites, while ensuring the independence of content on each site, is a challenge faced by many operators.The "multi-site management" feature provided by AnQiCMS is designed to solve this pain point.It not only allows you to manage all sites in a single background, but also fundamentally ensures that the content of each site is displayed independently, avoiding confusion and errors.So, AnQiCMS

2025-11-07

How to set the display logic and hierarchy of breadcrumb navigation in AnQiCMS template?

When building a website, breadcrumb navigation not only effectively improves user experience and helps visitors understand their current location, but is also an indispensable part of search engine optimization (SEO), as it clearly shows the hierarchical structure of the website.For websites using AnQiCMS to manage content, flexibly setting the display logic and hierarchy of breadcrumb navigation is an important task in template creation.AnQiCMS provides a powerful and easy-to-use template tag for handling breadcrumb navigation, allowing you to easily implement it in the front-end template without writing complex backend logic

2025-11-07

How to display custom product parameters and specifications on the product detail page?

Add custom parameters and specifications to the product detail page in AnQiCMS, which can make your product information more detailed and professional.Whether it is the technical parameters of electronic products or the size and color options of clothing, you can easily achieve these personalized display requirements through a flexible content model.Next, we will step by step understand how to set, fill in, and finally display these customized parameters and specifications on your product detail page.--- ### Step 1: Define product custom parameters in the background Start adding custom parameters to the product

2025-11-07

How to correctly display the list of related articles on the content detail page in AnQiCMS?

On AnQiCMS content detail page, displaying related article lists can effectively guide visitors to browse more content, reduce the bounce rate, and enhance the website's SEO performance through internal link structure.AnQiCMS is a system designed specifically for content operations, providing flexible and powerful template tags, allowing us to easily achieve this function.How does AnQiCMS recognize and display related articles?To make the content detail page intelligently display a list related to the current article, AnQiCMS provides a straightforward mechanism

2025-11-07

How does the AnQiCMS template format timestamps and display them in a specified date and time format?

In AnQiCMS template, easily format timestamps: Custom date and time display guide In website operation, content publishing time, update time, comment time, and other date information are an important part of the information we convey to visitors.Most of the time, the time data obtained from the database is usually a timestamp (a string of numbers), which is not intuitive for users.How to convert these original timestamps into a readable date and time format, and flexibly adjust the display according to the page design, which is a frequently encountered demand in template development. AnQiCMS

2025-11-07

How to display the title and link of the previous and next articles on the article detail page?

In AnQi CMS, adding the titles and links of the previous and next articles to the article detail page can not only optimize the user experience on your website, guide them to discover more related content, but also improve the internal link structure of the website to a certain extent.AnQi CMS with its simple and efficient template engine makes the implementation of this feature very intuitive.### Core Feature Revelation: prevArchive and nextArchive Tags The AnQi CMS template system is built-in with two tags specifically designed for handling article navigation: `prevArchive`

2025-11-07

How to implement batch replacement of specific keywords in article content and display it on the front end in AnQiCMS?

In the daily work of content operation, we often encounter the need to make uniform adjustments to a large amount of article content.This may involve updating the brand name, correcting industry terminology, unify the product model, and even adjusting keyword density for SEO purposes.Manually modifying hundreds or even thousands of articles one by one is undoubtedly a huge task and is prone to errors.AnQiCMS provides a very practical feature that can help us efficiently implement batch replacement of specific keywords in article content and ensure that these changes are displayed correctly on the website front-end.Why do you need to replace keywords in articles in bulk

2025-11-07

How to display custom field content of different content models in the frontend template?

The content model feature of AnQiCMS brings great flexibility to website operations, allowing us to define various personalized content structures according to our actual business needs.Whether it is an article, product, event, or any other custom content type, we can add unique fields for it.How can we flexibly display custom fields in the content model on the website front-end template?Let's explore this practical skill together. ### Understanding AnQiCMS's Content Model and Custom Fields Using AnQiCMS

2025-11-07