How to get all category lists under a specified model in AnQi CMS?

Calendar 👁️ 68

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

Related articles

How to get and display category thumbnails or Banner carousel?

The attractiveness of visual content is crucial in website operation.A well-designed category thumbnail and an eye-catching banner carousel not only beautifies the website interface but also effectively guides users to browse, enhancing the overall professionalism and user experience of the website.AnQiCMS (AnQiCMS) offers powerful and flexible features that allow you to easily manage and display these important visual elements.This article will provide a detailed introduction on how to obtain and display category thumbnails or Banner carousel in Anqi CMS.

2025-11-08

How to display the name, description, content, and link of the category?

When building a website, category information is not only the skeleton of the content, but also the key to user navigation, search engine optimization (SEO), and improving user experience.AnQiCMS (AnQiCMS) with its flexible template engine allows you to easily display categories, descriptions, content, and links on the website frontend, providing visitors with a clear navigation path and rich information for search engines to better understand your website structure.This article will delve into how to flexibly call and display your website's category information through several core tags in the AnQiCMS template.

2025-11-08

How to retrieve and display the custom parameter fields of the document in Anqi CMS?

AnQi CMS is loved by content operators for its excellent flexibility and highly customizable nature.In daily website management, we often encounter scenarios where it is necessary to add exclusive attributes for different types of content (such as articles, products, events, etc.)At this time, the document custom parameter field function of Anqi CMS can fully display its strength, allowing us to expand the structure of content according to business needs, thus achieving more personalized and rich display effects.

2025-11-08

How to display the links to the previous and next documents on the document detail page?

In website operation, providing a smooth user experience is crucial, and the previous and next navigation on the document detail page is the key to improving user experience and guiding users to deeply browse the website content.In AnQiCMS (AnQi CMS), implementing this feature is simple and efficient, it comes with dedicated template tags that allow you to easily add this practical feature to your website content. ### The Importance of Navigation Between Articles After users finish reading a document, they often want to find related or the next article to get more information.

2025-11-08

How to implement multi-level category nesting display in Anqi CMS?

The organization of website content is crucial for user experience and information retrieval efficiency.A clear and logical classification system can help visitors quickly find the information they need, and also lay a good foundation for the website's SEO.In Anqi CMS, implementing nested display of multi-level categories is the key to building this efficient content architecture.It is not just to list categories simply, but also to modularize and organize the content through hierarchical relationships, whether it is product display, article archive, or service introduction, it can be presented to users in a more intuitive way.

2025-11-08

How to retrieve custom fields of a category on the category detail page?

When managing website content in AnQi CMS, we often need to make the category page not just a simple aggregation of document lists, but also able to carry more exclusive information to better guide users or display the characteristics of the category.It is particularly important to add and obtain custom fields for categorization at this time.By using these custom fields, you can make each category page unique, whether it's displaying a specific banner image, contact information, or the unique properties of the category.

2025-11-08

How to display the complete content and all fields of a single page?

In Anqi CMS, a single page is the basis for building static content pages such as 'About Us' and 'Contact Information'.Effectively displaying the complete content of these pages and all their fields is crucial for website customization and user experience.The Anqi CMS provides intuitive and powerful template tags, allowing you to easily display single-page data configured in the background on the website front-end. To display the complete content of a single page and all related fields, we mainly use the `pageDetail` core template tag.

2025-11-08

How to retrieve and display all single page lists in AnQi CMS?

Managing and displaying single pages in Anqi CMS is one of the basic functions for website content construction.A single page is usually used to create pages with relatively fixed structures and independent content, such as 'About Us', 'Contact Information', or 'Service Introduction', etc.If you wish to display a list of single pages in a specific area of the website, such as the footer navigation or sidebar, AnQi CMS provides a very intuitive and flexible way to achieve this.

2025-11-08