The Anqi CMS is designed with a flexible content model, making content management efficient and elastic.Whether it is an enterprise official website, a marketing website, or a personal blog, there may be a need to display the corresponding category list based on different content models (such as articles, products, or custom models).Understanding how to accurately obtain these categories in the template is a key step to fully utilize the powerful functions of Anqi CMS.

In the Anqi CMS, the content model is the foundation for organizing content.System default built-in "Article Model" and "Product Model", and you can also create any number of custom content models according to your business needs.Each category is tightly bound to a specific content model, which means that when we talk about 'retrieving the list of all categories under a specified content model', we must first clarify which content model the target is.

The core lies in the flexible use of the AnQi CMS providedcategoryListTemplate tags. This tag is designed to be very powerful, helping us easily obtain and display the required category data on the front-end page.

Precise localization:categoryListCore parameters of the tag.

To get the category list under a specific content model,categoryListThere are two key parameters that we need to pay attention to for the tags:moduleIdandallorparentId.

FirstlymoduleIdThis parameter is the key to obtaining the specified model classification. It allows you to explicitly tell the system which content model you want under the classification. For example, if the ID of your article model is1, the product model ID is2, then you can setmoduleId="1"ormoduleId="2"Specify the target model. You can find the specific model ID in the 'Content Management' -> 'Content Model' section of the AnQi CMS backend.

ThenallParameters. If you need to list all categories under a model, whether they are top-level categories or subcategories,all=trueit comes in handy. Set it totrueThe system will help you find all categories under this model and return them in a flat list format, for your custom processing convenience.

In addition, if you are only concerned about the top-level categories under a specific model rather than all levels of categories, you can combine their use.parentId="0"This will tell the system to only return those categories without parent categories (i.e., the top-level categories).

Practice Operation: Get and display the category list

Below we demonstrate how to use several practical examplescategoryListTags to get the categories under a specified model.

Example 1: Get all top-level categories under a specified model

假设我们想在网站首页侧边栏显示“文章”模型下的所有顶级分类。首先,我们需要知道“文章”模型对应的moduleId。通常情况下,文章模型的ID是English1.

{# 获取“文章”模型(moduleId="1")下的所有顶级分类 #}
<div class="category-list">
    <h3>文章分类</h3>
    <ul>
        {% categoryList categories with moduleId="1" parentId="0" %}
            {% for item in categories %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
                    {# 如果需要,可以判断是否有子分类并进行提示 #}
                    {% if item.HasChildren %}
                        <span>(有子分类)</span>
                    {% endif %}
                </li>
            {% endfor %}
            {% empty %}
                <li>暂无文章分类</li>
        {% endcategoryList %}
    </ul>
</div>

In this code,moduleId="1"明确指定了文章模型,而EnglishparentId="0"则确保我们只获取顶级分类Englishitem.LinkIt will output the access link of the classification,item.Title则显示分类名称,`item.HasEnglish