How to display the category list in AnQiCMS and support multi-level nested display?

Calendar 👁️ 61

The classification navigation of the website is the foundation of user experience and information architecture.A clear, easy-to-navigate category list, especially one that can support multi-level nesting, can greatly improve the efficiency of users searching for information and optimize the search engine's understanding of the website structure.AnQiCMS provides powerful and flexible template tags, allowing you to easily meet this requirement.

Basic category management in AnQiCMS

On the AnQiCMS backend, you can create and organize your website categories under the "Content Management" module.When creating a category, you can specify the content model it belongs to (such as articles, products, etc.), and set its parent category to build a clear hierarchy.For example, you can have a top-level category such as "News Center", and then create secondary categories such as "Company News", "Industry Information", etc.This kind of hierarchical structure is the foundation for multi-level nested display in front-end.

Core: UnderstandingcategoryListTag

The core tool used to retrieve category data in AnQiCMS templates iscategoryListThe label is very flexible. By adjusting its parameters, you can precisely control which categories to display and how they are displayed.

While usingcategoryListWhen, several key parameters need to be understood:

  • moduleId: Specify the category of the content model you want to retrieve. For example, if your article model ID is 1, and your product model ID is 2, by settingmoduleId="1"you can only retrieve article categories.
  • parentIdThis is the key parameter for achieving multi-level nesting. When you set it to0it will return all top-level categories. If you want to get the subcategories of a specific category, you can setparentIdSet the category obtained in the loopIdProperty.
  • limit: Controls the number of categories returned
  • siteId: If you have enabled the multi-site feature, you can specify which site to get the category data from using this parameter

IncategoryListlabel'sforIn the loop, each category item (usually nameditem), will provide some useful properties, such as:

  • item.Id: The unique identifier of the category.
  • item.Title: The display name of the category.
  • item.Link: The link address of the category page.
  • item.HasChildrenA boolean value indicating whether the current category contains subcategories, which is crucial for building dynamic nested menus.

Build a list of top-level categories

The simplest application is to display all top-level categories, which usually constitutes the main navigation of your website. You can usemoduleIdto specify the content model, and setparentId="0"to get all top-level categories.

{% categoryList categories with moduleId="1" parentId="0" %}
    <ul>{# 这将是一个无序列表,包含所有顶级分类 #}
        {% for item in categories %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {% endfor %}
    </ul>
{% endcategoryList %}

to achieve multi-level nested category display

To implement a multi-level nested category list, you can utilizecategoryListthe nested properties of tagsitem.HasChildrenattributes. Within the loop of each category, ifitem.HasChildrenWithtrue, callcategoryListtag again to get its child categories, andparentIdSet to the current category ofitem.Id. This can be used to build nested structures of any depth.

Here is an example of a nested three-level classification code, you can add or reduce levels according to your actual needs:

`twig {% categoryList categories with moduleId=“1” parentId=“0” %}

<ul class="main-category-list">{# 一级分类列表 #}
    {% for item in categories %}
        <li>
            <a href="{{ item.Link }}">{{ item.Title }}</a>
            {% if item.HasChildren %}
                <ul class="sub-category-list">{# 二级分类列表 #}
                    {% categoryList subCategories with parentId=item.Id %}
                        {% for subItem in subCategories %}
                            <li>
                                <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                {% if subItem.HasChildren %}
                                    <ul class="third-category-list">{# 三级分类列表 #}
                                        {% categoryList thirdCategories with parentId=subItem.Id %}
                                            {% for thirdItem in thirdCategories %}
                                                <li><a href="{{ thirdItem.Link }}">{{ thirdItem.Title }}</a></li>
                                            {% endfor %}
                                        {% endcategoryList %}
                                    </ul>
                                {% endif %}
                            </li>
                        {% endfor %}
                    {% endcategoryList %}

Related articles

How to display the banner image list on AnQiCMS template?

The visual elements of a website are crucial for attracting visitors and conveying brand information, and the Banner image list is one of its core components.AnQiCMS as a powerful content management system provides a flexible way to display these banner images on your website template, whether it be for the homepage slideshow, category page feature images, or single-page promotional images, all can be easily realized through concise template tags.

2025-11-08

How to display the details and list of a custom single page in AnQiCMS?

In AnQiCMS, the Single Page (Page) feature provides the website with the powerful ability to display independent and fixed content, such as 'About Us', 'Contact Information', 'Company Profile', and other pages.These pages usually do not belong to a specific category, but exist independently, carrying important corporate information or brand stories.Efficiently create, manage, and flexibly display the details and lists of these single pages on the website, which is an indispensable part of content operation.

2025-11-08

How to configure and display the contact information of the AnQiCMS website, such as phone number, address, and social media?

The contact information of the website is crucial for establishing a connection and providing support to users.AnQiCMS (AnQiCMS) provides an intuitive and flexible way to manage and display this important information, whether it's phone numbers, addresses, or various social media platform links, all can be easily achieved. ### Configure the website contact information in the background To configure the website contact information, you can first log in to the Anqi CMS backend management interface.In the left navigation bar, find and click "Background Settings", then select "Contact Information Settings".Here is a collection of all the contact information you may need to display

2025-11-08

How to display different content and manage interfaces for multiple sites in the AnQiCMS website?

AnQiCMS, with its powerful multi-site management functions, provides an efficient and flexible solution for operators with multiple brands, sub-sites, or content branches.It allows you to easily create, manage, and display multiple independently operated websites under the same core system, greatly enhancing the efficiency of content operation.

2025-11-08

How to display detailed information of a specific category in AnQiCMS, including its introduction and Banner image?

In AnQiCMS, the category page is not just a simple list of content, but also an important part of the website's information architecture, and a key entry point to display specific themes and guide users to further browsing.A well-designed category page that not only enhances user experience but also effectively optimizes search engine rankings.This article will provide a detailed introduction on how to flexibly display specific category details in AnQiCMS, including its introduction and beautiful Banner images.

2025-11-08

How to control the generation method and size of image thumbnails in AnQiCMS to optimize display effects?

AnQiCMS provides a powerful and flexible image processing mechanism in website content management, among which the generation method and size control of image thumbnails are key to optimizing the display effect of the website, enhancing user experience, and accelerating page loading speed.Through the various built-in functions of the system, we can easily manage the thumbnail images with fine precision, ensuring that the website images are presented in **status across different scenarios. ### Thumbnail Image: An Important Aspect of Website Optimization Images on a website are not just visual elements, but also carriers of content conveyance and user experience.

2025-11-08

How to display website visitor traffic statistics and spider crawling records in AnQiCMS?

In website operation, a deep understanding of visitor behavior and the activity track of search engine crawlers is crucial for optimizing website content, improving SEO effects, and enhancing user experience.AnQiCMS as a comprehensive content management system fully considers this point, providing users with convenient traffic statistics and web crawler capture record functions to help us more effectively analyze website performance.

2025-11-08

How to remove blank lines generated by logical tags in AnQiCMS to optimize page display?

In website operation and front-end development, the neatness of the HTML structure of the page plays an indispensable role in maintaining code readability, improving development efficiency, and optimizing page rendering in certain situations. When using AnQiCMS and similar content management systems for template development, we often encounter a common but easily overlooked problem: logical tags (such as conditional judgment `if`, loop `for`, etc.) may introduce extra blank lines during rendering, resulting in the generated HTML code being not aesthetically pleasing and even causing unexpected visual effects in some layouts with strict layout requirements.

2025-11-08