How to display the subcategory list under the AnQiCMS category page?

Calendar 👁️ 60

In AnQiCMS, you can easily display the subcategory list under the category page with flexible template tags.It is crucial for building a clear website structure, enhancing user navigation experience, and optimizing search engine crawling efficiency.AnQiCMS has a powerful template system and its Django-style tag syntax, making the display of this dynamic content intuitive and efficient.

To implement the display of the subcategory list under the category page, the following steps are mainly involved:

1. Understand the template structure and tag usage of AnQiCMS

AnQiCMS template files are usually named with.htmlsuffix and stored in/templatedirectory. It uses a syntax similar to Django template engine, with variables enclosed in double curly braces{{变量}}Comma, conditional judgment and loop control tags use single curly braces and percent signs{% 标签 %}On the category page, the core lies in using the provided by AnQiCMScategoryList.

Generally, category pages use model-specific list templates, such as the category list page for the article model might bearticle/list.htmlor a custom template file for a specific category that you have created in the backend.

Second, get the current category information and model ID

On the category list page, you first need to obtain some basic information about the current category, especially its ID and the ID of the model it belongs to. This can be done bycategoryDetailtags. AlthoughcategoryListWhen calling on the current category page, it can usually intelligently obtain its subcategories, but explicitly obtain the ID and model ID of the current category and pass them tocategoryListLabels can make the code more robust and readable.

For example, you can get the details of the current category at the appropriate location in your category template file:

{# 假设您正在一个分类的列表页,并且希望显示当前分类的子分类。 #}

{# 1. 首先,获取当前分类的详细信息,这能帮助我们确定模型ID以及作为父ID。 #}
{% categoryDetail currentCategoryDetail %}
    {# 此时,currentCategoryDetail 对象包含了当前分类的所有信息,例如: #}
    {# {{ currentCategoryDetail.Title }} - 当前分类的标题 #}
    {# {{ currentCategoryDetail.Id }} - 当前分类的ID #}
    {# {{ currentCategoryDetail.ModuleId }} - 当前分类所属模型的ID #}
    {# 您可以根据需要显示这些信息,例如作为页面标题或面包屑导航的一部分。 #}
    <div class="current-category-info">
        <h1>{{ currentCategoryDetail.Title }}</h1>
        <p>{{ currentCategoryDetail.Description }}</p>
    </div>

    {# 接下来,我们就可以使用这些信息来获取其下属子分类。 #}
{% endcategoryDetail %}

3. UsecategoryListLabels to display subcategory lists

Get the current categoryIdandModuleIdAfter that, you can callcategoryListThe tag to get the direct subordinate child categoriescategoryListThe tag supports multiple parameters, includingparentIdandmoduleIdIt is the key.

  • parentIdSet to the parent category ID you want to retrieve the subcategory. That is, the one above.currentCategoryDetail.Id.
  • moduleIdSpecify the ID of the content model you belong to. This can also be obtained fromcurrentCategoryDetail.ModuleIdGet, ensure that you are getting the correct model's subcategory.

This is a complete example showing how to obtain and display the list of sub-categories under a category page, while also considering the possibility that sub-categories may contain deeper-level sub-categories:

`twig {# Assume you are on a category list page and want to display the subcategories of the current category. #}

{# 1.First, obtain the detailed information of the current category, which helps us determine the model ID and the parent ID.

<div class="current-category-info">
    <h1>{{ currentCategoryDetail.Title }}</h1>
    <p>分类简介:{{ currentCategoryDetail.Description }}</p>
    {# 更多当前分类的信息可以在这里显示,如Banner图、缩略图等 #}
    {%

Related articles

How does AnQiCMS display the list of all top-level categories?

In website construction and content operation, clear classification navigation is the foundation of user experience, as well as the core of content organization.For users using AnQiCMS, how to efficiently display the list of all top-level categories of the website is the first step in building the website structure.AnQiCMS with its flexible template engine and rich built-in tags makes this task exceptionally simple and intuitive.

2025-11-08

How to filter and display a specific list of articles based on recommended properties (Flag) in AnQiCMS?

An QiCMS provides operators with rich tools for organizing and displaying website content with its flexible and efficient content management capabilities.Among the "recommended attributes" (Flag) is a very practical feature that allows you to easily categorize and mark articles, thereby enabling accurate content filtering and dynamic display on the website front end.This article will introduce in detail how to use these recommended attributes in AnQiCMS to filter and display the specific article list you want.### Deep Understanding of AnQiCMS Recommendation Attributes (Flag) AnQiCMS Recommendation Attributes

2025-11-08

How to nested display the list of articles under the category page in AnQiCMS?

In website operation, the content classification page carries the important responsibility of organizing information and guiding users to browse.A well-designed and content-rich category page can not only improve user experience but also optimize search engine crawling efficiency.For users of AnQiCMS, nesting the list of articles under the category page is a very basic and commonly used feature.This article will introduce you in detail on how to use the powerful template tags of Anqi CMS to easily achieve this goal.Understanding the Classification Page and Content Model Before we begin

2025-11-08

How to judge and highlight the first article in the AnQiCMS article list loop?

In website content display, we often encounter the need to handle the first element of the article list specially.In order to achieve visual prominence, to implement unique layout design, or to give the first article more attention, AnQiCMS provides flexible and powerful template tags to help us easily achieve this goal.AnQiCMS uses a syntax similar to the Django template engine, where the `for` loop tag plays a core role in processing content lists.When we use `archiveList`

2025-11-08

How to implement nested display of multi-level categories in AnQiCMS navigation menu?

In website construction, a clear and easy-to-use navigation menu is crucial for improving user experience and the overall structure of the website.AnQiCMS provides flexible settings for managing the navigation menu, allowing users to easily implement nested hierarchical classification display, thereby better organizing website content and guiding visitors to explore.To implement multi-level nested navigation, we mainly complete it through the "Navigation Settings" function in the AnQi CMS backend.This feature is located in the "Background Settings" area, it can not only manage the top navigation of the website, but also create various custom navigations as needed

2025-11-08

How to obtain and display the detailed description information of AnQiCMS categories?

In website operation, clear and detailed classification descriptions are crucial for user experience and search engine optimization.AnQiCMS as a powerful content management system provides a flexible way to manage and display these category information.This article will delve into how to retrieve and effectively display detailed category descriptions on the frontend page in AnQiCMS.

2025-11-08

How to call and display the Banner image of the AnQiCMS category page

In website operation, the category page is not only the display of content classification, but also a key entry for users to explore the website and gain a deeper understanding of products or services.A well-designed category banner image that can effectively enhance the visual appeal of the page, strengthen the brand image, and guide users to the next step of operation.AnQiCMS as an efficient content management system, provides a flexible way to manage and call these banner images. We will delve into how to set up a Banner image for category pages in AnQiCMS and display it on the website frontend.###

2025-11-08

How to create a custom template for AnQiCMS website to achieve personalized display?

AnQiCMS with its flexible and efficient features provides a wide space for personalized display of website content.If you want your website to have a unique look and function, creating a custom template is undoubtedly the way.By deeply customizing the template, you can fully control every detail of the website, from brand image to user experience, achieving high levels of personalization and standing out among many websites.This article will guide you to understand how to create and apply custom templates in AnQiCMS, helping you to turn your design ideas into reality and realize the personalized display of the website

2025-11-08