How to use `categoryList` to build a flat list of all categories without hierarchy display?

Calendar 👁️ 69

As an experienced website operation expert, I know that it is very important to flexibly display category lists when building the content structure of a website.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template tag system.categoryListLabel, elegantly build a flat list of all categories so that all categories are clearly displayed on your website without levels.

1. Why do we need a flat category list?

In content management, we often need a tree-like, hierarchical classification structure to organize content, which helps users gradually delve into specific topics. But sometimes, we also need a more direct, more comprehensive way to display all categories, such as:

  • Sitemap pageUsers want to see the scope of all the content on the website at a glance.
  • Footer navigation at the bottom of the pageProvide an overview of the website content, allowing users to quickly jump to any category.
  • Recommended content area: Guide users to discover more interests in the form of tag clouds or popular categories.
  • Data statistics or management viewIn some customized management interfaces, it may be necessary to view all categories without concerning their hierarchical relationships.

In this scenario, AnQiCMS'categoryListA label combined with a clever parameter can perfectly meet our needs.

Part two: UnveilingcategoryListThe core capability of the label

Of Security CMScategoryListThe tag is a universal tool used to obtain the classification list of content models such as articles, products, etc.It is powerful, can get child categories under a specific parent, and can also filter categories under a specific model.all=true.

Generally speaking, when we usecategoryListand specifyparentId="0"At this time, we get the top-level category. However, if your category structure is hierarchical, merely obtaining the top-level category is not sufficient to display all. At this point,all=trueThe parameter comes into play, it indicates that the system should ignore the hierarchical relationship and extract all matching categories at once.

At the same time, we also need to pay attention tomoduleIdThe parameter helps us accurately specify whether to retrieve all categories under the "Article Model" or all categories under the "Product Model", or categories under other custom models.This ensures that the list we obtain is relevant and meaningful.

Step 3: Get hands-on: Build a flattened classification list

Now, let's see how to use a real code example tocategoryListbuild a flattened list of all classifications.

Assuming we want to display all article category links at the bottom of the website, not hierarchical, in list form.

<div class="footer-categories">
    <h3>探索更多分类</h3>
    <ul>
        {#
            使用 categoryList 标签获取所有分类。
            - all=true: 告诉系统获取所有分类,忽略层级。
            - moduleId="1": 指定我们只获取“文章模型”下的分类 (通常文章模型ID为1,请根据您的实际后台配置调整)。
            - categories: 我们将获取到的分类列表命名为 categories,方便后续在for循环中使用。
        #}
        {% categoryList categories with all=true moduleId="1" %}
            {# 遍历获取到的每一个分类项 #}
            {% for item in categories %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {{ item.Title }}
                </a>
            </li>
            {% endfor %}
        {% endcategoryList %}
    </ul>
</div>

In this code block:

  1. We first defined adivA container to hold our flattened classification list.
  2. {% categoryList categories with all=true moduleId="1" %}Is the key point.
    • all=true: This is the core to achieve flattened display. It will.categoryListReturn all classifications, regardless of their level.
    • moduleId="1"Assuming your article model ID is 1. If you want to get the product categories, you may need to change it tomoduleId="2"(Please confirm the specific ID according to your Anqi CMS backend content model settings).This parameter ensures that we only obtain categories under specific content models, avoiding the mixing of unrelated categories (such as product categories mixed into article category lists).
  3. {% for item in categories %}We use a standardforto loop throughcategoryListlabel to return each category item.
  4. Inside the loop,{{ item.Link }}The link address of the category will be output,{{ item.Title }}The category name will be output. We have deliberately avoided usingitem.Spaceroritem.HasChildrensuch fields related to hierarchical structure to keep the list completely flat.

Through such settings, no matter how complex your classification structure is (first-level classification, second-level classification, third-level classification), the final display on the front end will be a simple classification list without hierarchical feeling.

Step 4: Advanced Thinking and Adjustment

  • Limit the Display Quantity: If your category number is large, you may not want to display all at once. You can addlimitparameters to control the number of categories displayed, for examplelimit="20"Display only the first 20 categories.
  • Specify multiple content models: If you need to display categories from different content models while still keeping them flat,categoryListCurrently does not support specifying multiple at the same timemoduleIdYou may need to call them separatelycategoryListTags, then merge the results, or manage the category sets that need to be displayed more finely through the backend.
  • Add simple styleThe above code only shows the structure, you can use CSS to.footer-categoriesbelowulandliAdd style to make it beautiful and generous, for example, adjust font size, spacing, or achieve horizontal alignment, etc.

Summary

Of Security CMScategoryListLabel collaborationall=trueParameters provide website operators with an extremely convenient way to build a flat list of all categories.This flexibility allows us to easily adjust the content display strategy of the website according to different operational needs, whether it is to improve SEO effects or to enhance the user navigation experience, it provides strong support.Master this skill, and you will be more proficient in website content operation.


Frequently Asked Questions (FAQ)

Q1: How can I only display the top-level categories instead of all categories?A1: If you want to display only the top-level categories, not all hierarchical categories, you need toall=trueremove the parameter and make sure that theparentId="0". For example:{% categoryList categories with moduleId="1" parentId="0" %}This way, the system will only return the top-level categories without any parent category.

Q2: Can I only get all categories under a specific content model (such as "Product Model")?A2: Of course you can. You just need to adjustmoduleIdthe parameters. For example, if your product model ID is2, you can use it like this:{% categoryList categories with all=true moduleId="2" %}This ensures that the list only contains product-related categories.

Q3: How to sort all flattened displayed categories, such as by name in alphabetical order?A3:categoryListThe tag itself in obtaining all categories (all=true) was not provided directly in the documentorderParameters to control the sorting method of the returned results.The display order of categories usually follows the category sorting you set in the AnQiCMS backend.If you need more complex sorting (such as by name initials), you may need to consider sorting the list you get on the front end through JavaScript, or customizing the query logic of the category list on the back end (this usually requires development support outside of the template engine).

Related articles

`categoryList` can exclude certain specific category IDs from displaying in the list?

As an experienced website operations expert, I know how important it is to have fine control over the list content in content management.Especially in the context of increasingly complex website structures and increasingly rich content, how to flexibly display or hide specific content is directly related to user experience and operational efficiency.Today, let's delve into a common but cleverly handled requirement in AnQiCMS (`categoryList` tag) - whether it can exclude certain specific category IDs from displaying in the list.###

2025-11-06

When will the `item.Content` field be used in the `categoryList` loop, can it display rich text content?

HelloAs an experienced website operations expert, I am willing to deeply analyze the application of the `item.Content` field in the `categoryList` loop of AnQiCMS (AnQiCMS), as well as how to elegantly display rich text content.

2025-11-06

How to avoid `categoryList` automatically reading the current page category ID and force it to only display top-level categories?

In the flexible content management world of Anqi CMS, template tags are the bridge between us and data interaction.Among them, the `categoryList` tag is undoubtedly one of the core tools for building website navigation and content lists.However, senior operators often encounter a scene: when the website is on a specific category page, the `categoryList` tag will 'intelligently' read the current category ID and use it as the context for data display.This is extremely convenient in many cases, such as displaying the subcategories or peer categories of the current category.

2025-11-06

Does the `categoryList` tag support custom sorting rules to display the category list? (The document does not directly mention it, but it can be explored)

As an experienced website operations expert, I know that how to flexibly display and organize content in a content management system is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) provides a solid foundation for content operation with its efficient and customizable features.Today, let's delve deeply into a core issue about the `categoryList` tag: does it support custom sorting rules to display the category list?### Category List Label in AnQi CMS: `categoryList` Overview In AnQi CMS

2025-11-06

How to avoid performance issues when the `categoryList` tag is used with large amounts of data?

As an experienced website operations expert, I have accumulated rich experience in content management and performance optimization, especially familiar with many functions of AnQiCMS.In daily operations, we often encounter problems such as large amounts of website classification data, leading to slow page loading and increased server pressure.This is often one of the key factors affecting performance, the way the `categoryList` tag is used.

2025-11-06

How to add custom HTML styles or CSS classes to the category names returned by `categoryList`?

As an experienced website operations expert, I am well aware that the readability and visual aesthetics of website content are crucial for user experience, and the flexible template customization capability is the key to achieving this goal.In AnQiCMS, even for a simple category list, we have multiple ways to add personalized HTML styles or CSS classes to enhance the overall attractiveness and functionality of the website.Today, let's delve into how to assign custom styles to the category names returned by `categoryList`

2025-11-06

What is the corresponding relationship between the `categoryList` tag in template development and the background "document classification" function settings?

As an experienced website operation expert, I deeply understand that the core value of a Content Management System (CMS) lies in the seamless connection between the backend configuration and the frontend display.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture based on the Go language and flexible design.Today, let's delve deeply into the development of the Anqi CMS template and the `categoryList` tag, how it closely corresponds to the background "Document Category" function, and how we巧妙运用 this correlation to build powerful website functions.##

2025-11-06

When should the `categoryList` tag be used instead of the `navList` tag to build website navigation?

In the flexible and powerful template system of AnQiCMS, building website navigation is one of the basic tasks of content operation.We often encounter two seemingly similar but distinct tags: `categoryList` and `navList`.As an experienced website operations expert, I am well aware of how to cleverly use these tools according to the specific needs of the website to achieve **user experience and content management efficiency.Today, let's delve deeper into when we should prioritize `categoryList` over

2025-11-06