How to display the document category list at different levels in Anqi CMS and its associated documents?

Calendar 👁️ 118

How to efficiently organize and display a large amount of content in website operation is the key to improving user experience and website usability.For friends using AnQiCMS, the system provides powerful content model and template tag features, which can help us easily implement multi-level document classification lists and clearly display the associated documents under each category.

Next, let's explore how to build a website navigation with both hierarchy and rich content using these features in Anqi CMS.

Understand the content structure of Anqi CMS

In Anqi CMS, the content is mainly constructed around the two core concepts of 'content model' and 'classification'.The content model (such as article model, product model) defines the type of content and its unique fields, and the category is the organizational structure under these content models.Each document (whether an article or a product) will belong to a specific category.

To display different levels of document categories and associated documents, we mainly use two key template tags of Anqicms:categoryListUsed to obtain category information, as well asarchiveListUsed to retrieve the document list.

Get the top-level document category list

Firstly, we need to display the top-level categories in the template. This is usually the basis of the website's main navigation. We can usecategoryListLabel, and throughparentId="0"Specify to get all top-level categories without a parent. Also, don't forget to go throughmoduleIdThe parameter specifies whether to get the article model (usually1) or the product model (usually2) category.

A simple example to show the top-level category list of the article model:

{% categoryList categories with moduleId="1" parentId="0" %}
    <ul>
        {% for item in categories %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {% endfor %}
    </ul>
{% endcategoryList %}

In this code block,categoriesIs the variable name defined for the top-level category list,itemIs the instance of each category in the loop.item.LinkWill automatically output the access link of the category,item.TitleThen it will display the category name.

Displays multi-level subcategories

The website structure is often not just one layer. Anqi CMS'scategoryListTags support nested usage, allowing us to further display child categories under the top-level category. This is due toitemWithin the objectHasChildrenfield, which can determine whether the current category has child categories.

If a category has subcategories, we can call it again within itcategoryListand use the current category'sIdasparentIdPass the query to the subcategory so that it can expand layer by layer

Consider displaying a two-level category:

{% categoryList topCategories with moduleId="1" parentId="0" %}
    <ul class="main-nav">
        {% for category in topCategories %}
            <li>
                <a href="{{ category.Link }}">{{ category.Title }}</a>
                {% if category.HasChildren %} {# 判断当前分类是否有子分类 #}
                    <ul class="sub-nav">
                        {% categoryList subCategories with parentId=category.Id %} {# 获取当前分类的子分类 #}
                            {% for subCategory in subCategories %}
                                <li><a href="{{ subCategory.Link }}">{{ subCategory.Title }}</a></li>
                            {% endfor %}
                        {% endcategoryList %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endcategoryList %}

So, we can see a clear second-level category navigation structure on the website. If more levels are needed, you can continue nesting according to this pattern.categoryList.

Associate and display the documents under each category.

It's not enough to just display the category names, users want to see the specific content under each category. At this point,archiveListtags come into play. We can call them while displaying categories in a loop,archiveListTo display the documents under the current category.

The key is to classify the current category.Idpass toarchiveListofcategoryIdParameters, in this wayarchiveListIt will only retrieve the documents belonging to the current category. To make the page tidy, we usually limit the number of displayed documents, usinglimitParameters can be easily implemented.

For example, display the latest 5 documents under each category:

{% categoryList categories with moduleId="1" parentId="0" %}
    <div class="category-section">
        {% for cat in categories %}
            <h3><a href="{{ cat.Link }}">{{ cat.Title }}</a></h3>
            <ul class="document-list">
                {% archiveList docs with type="list" categoryId=cat.Id limit="5" %} {# 获取当前分类下的5篇文档 #}
                    {% for doc in docs %}
                        <li><a href="{{ doc.Link }}">{{ doc.Title }}</a></li>
                    {% empty %} {# 如果当前分类下没有文档 #}
                        <li>暂无相关文档。</li>
                    {% endfor %}
                {% endarchiveList %}
            </ul>
        {% endfor %}
    </div>
{% endcategoryList %}

Comprehensive example: Build a complete hierarchical navigation and content list

Now, let's combine the aforementioned concepts to build a complete example that can display multi-level classifications and associated documents under each classification.A common requirement is that if a category has subcategories, the subcategory list should be displayed;If there are no subcategories, directly display the documents under the category.

`twig {# Assuming we are creating a product list page, the product model ID is 2 #}

{% categoryList productCategories with moduleId="2" parentId="0" %} {# 获取产品模型的顶级分类 #}
    <ul class="main-categories">
        {% for mainCategory in productCategories %}
            <li>
                <a href="{{ mainCategory.Link }}">{{ mainCategory.Title }}</a>
                {% if mainCategory.HasChildren %} {# 如果有子分类,则显示子分类 #}
                    <ul class="sub-categories">
                        {% categoryList subCategories with parentId=mainCategory.Id %} {# 获取子分类 #}
                            {% for subCategory in subCategories %}
                                <li>
                                    <a href="{{ subCategory.Link }}">{{ subCategory.Title }}</a>
                                    {# 可以在这里继续嵌套显示三级分类,或直接显示文档 #}
                                    {% if subCategory.HasChildren %}
                                        <ul class="tertiary-categories">
                                            {% categoryList tertiaryCategories with parentId=subCategory.Id %}
                                                {% for tercat in tertiaryCategories %}
                                                    <li><a href="{{ tercat.Link }}">{{ tercat.Title }}</a></li>
                                                {% endfor %}
                                            {% endcategoryList %}
                                        </ul>
                                    {% else %}
                                        {# 如果没有三级分类,则直接显示该二级分类下的产品文档 #}
                                        <ul class="associated-products">
                                            {% archiveList products with type="list" categoryId=subCategory.Id limit="4" %}
                                                {% for product in products %}
                                                    <li>
                                                        <a href="{{ product.Link }}">
                                                            <img src="{{ product.Thumb }}" alt="{{ product.Title }}" />
                                                            <span>{{ product.Title }}</span>
                                                        </a>
                                                    </li>
                                                {% empty %}
                                                    <li>该分类暂无产品。</li>
                                                {% endfor %}
                                            {% endarchiveList %}
                                        </ul>
                                    {% endif %}
                                </li>
                            {% endfor %}
                        {% endcategoryList %}
                    </ul>
                {% else %} {# 如果没有子分类,则直接显示该顶级分类下的产品文档 #}
                    <ul class="associated-products">
                        {% archiveList products with type="list" categoryId=mainCategory.Id limit="4" %}
                            {% for product in products %}
                                <li>
                                    <a href="{{ product.Link }}">
                                        <img src="{{ product.Thumb }}" alt="{{ product.Title }}" />
                                        <span>{{ product.Title }}</span>

Related articles

How to filter and display a specific list of documents based on keywords in AnQi CMS?

When using Anqi CMS to manage website content, we often need to search and display related document lists based on specific keywords.It is crucial to master the keyword filtering method, whether it is to create an in-site search results page or to display content closely related to a theme on a specific topic page.The AnQi CMS provides flexible and powerful template tag functions, making this task intuitive and efficient.### The foundation of keyword filtering: `archiveList` tag's `q`

2025-11-09

How to use the global settings of Anqi CMS to unify the display of copyright information and contact details on the website?

In website operation, copyright statements and contact information are important components for building brand trust, providing user support, and ensuring legal compliance.AnQiCMS (AnQiCMS) fully understands the importance of this information, and therefore provides an intuitive and powerful global setting function, allowing website administrators to uniformly and conveniently control the display of these contents without frequent code modifications.Imagine if your website has hundreds of pages and you need to manually edit each page every time you update the copyright year or customer service phone number, it would be such a繁琐 and error-prone task.

2025-11-09

How to implement pagination functionality in Anqi CMS and customize the display style of page numbers?

In AnQi CMS, the pagination feature of website content is an indispensable part of improving user experience and optimizing site structure.Whether it is a list of blog articles, product display pages, or other dynamic content, reasonable pagination makes it easier for users to browse a large amount of information and also helps search engines better understand and extract website content.Today, let's delve deeper into how to implement pagination in AnQiCMS and customize the display style of page numbers according to your own needs. ### Why do we need pagination? Imagine that your website has hundreds or even thousands of wonderful articles.If there is no pagination

2025-11-09

How to correctly render Markdown content as HTML and display mathematical formulas or flowcharts in Anqi CMS?

In AnQi CMS, using Markdown format to write content not only improves editing efficiency, but also maintains the structuralization and readability of the content.When content involves complex mathematical formulas or a clear flowchart needs to be displayed, the strength of Markdown becomes evident.Our company provides good support for this, let's take a look at how to correctly render and display these advanced contents on the website.### Step 1: Enable Markdown Editor First, make sure that your CMS system has enabled the Markdown editor feature

2025-11-09

How to customize the Title and Description of Anqi CMS website to optimize search engine results display?

In today's highly competitive online environment, whether a website can stand out in search engines largely depends on its optimization of details.Among them, the page's Title (title) and Description (description) play a crucial role, as they are the 'business card' of the website presented on the search engine results page (SERP).Carefully customize these elements, which can not only help search engines better understand the page content, but also attract potential visitors to click, thereby improving the traffic and visibility of the website.AnQiCMS (AnQiCMS) as a powerful content management system

2025-11-09

How to implement independent management and unified display of multi-site content on the front end for AnQi CMS?

In today's digital age, many businesses and content operators face a common challenge: how to efficiently manage multiple brand websites, product sub-sites, or content platforms, ensuring that each site runs independently while also achieving flexible integration of content and resources?AnQi CMS is born to solve this pain point, it provides a set of elegant and practical solutions, making independent management and unified display of multi-site content accessible.One of the core strengths of AnQi CMS is its powerful multi-site management capability.When you need to operate multiple websites, such as a corporate website

2025-11-09

How to use the flexible content model of AnQi CMS to display different types of content structures (such as articles, products, events)?

The Anqi CMS provides a powerful core capability in content management, that is, its highly flexible content model.This feature allows us to freely define and organize various types of content according to the actual needs of the website, whether it is traditional articles and information, detailed product introductions, or time-sensitive event publications, all of which can be managed efficiently and orderly within the same system.It breaks free from the constraints of traditional CMS fixed content types, allowing us to focus more on the business logic itself rather than being restricted by the system framework

2025-11-09

How to configure and display multilingual content in AnQi CMS to meet the access needs of users from different regions?

Under the trend of globalization, providing multilingual content has become a basic requirement for websites to reach a wider audience.AnQiCMS (AnQiCMS) took this into consideration from the beginning of its design, providing users with an effective way to configure and display multilingual content through its powerful multi-site management and flexible template mechanism, to meet the needs of visitors from different regions.### Understanding the multilingual operation mechanism of AnQi CMS In AnQi CMS, the implementation of multilingualism is mainly divided into two levels: one is the language switching of the system backend and frontend interface

2025-11-09