AnQi CMS, with its flexible content model design, makes content management efficient and flexible.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 according to different content models (such as articles, products, or custom models).Understanding how to accurately retrieve these categories in the template is a key step to fully utilizing the powerful functions of Anqi CMS.

In AnQi CMS, the content model is the cornerstone of organizing content.The system is built-in with '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 'getting the list of all categories under a specified model', we first need to clarify which content model the target is.

The key to achieving this goal lies in flexibly using the features provided by Anqi CMScategoryListTemplate tag. This tag is very powerful and can help us easily obtain and display the required category data on the front-end page.

Accurate positioning:categoryListThe core parameter of the tag

To get the category list under a specific content model,categoryListThe label has two key parameters that we need to pay attention to:moduleIdandallorparentId.

FirstlymoduleId. This parameter is the key to obtaining the specified model classification. It allows you to explicitly tell the system which content model classification you want. For example, if your article model ID is1The product model ID is2Then you can set throughmoduleId="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.

Next isallparameter. 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 easy customization.

Also, if you are only concerned with the top-level categories under a certain model and not all hierarchical categories, then you can combine them usingparentId="0"This will tell the system to return only those categories that do not have a parent category (i.e., the top-level categories).

Practice operation: Get and display the category list

We will demonstrate how to use it with several practical examples.categoryListTags to get the categories under the specified model.

Example one: Get all top-level categories under the specified model.

Suppose we want to display all the top-level categories under the 'Article' model on the website homepage sidebar. First, we need to know the correspondingmoduleIdThe article model ID is usually1.

{# 获取“文章”模型(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 block,moduleId="1"Explicitly specified the article model, whileparentId="0"Then make sure we only get the top-level categories.item.LinkIt will output the access link of the category,item.TitleThen display the category name, `item.Has