How to use the AnqiCMS category list tag to display article/product categories by level or model on the front end?

Calendar 👁️ 73

In website content management, it is crucial to organize and present information efficiently. AnqiCMS provides a powerful template tag system, among whichcategoryListThe tag is a core tool used to flexibly display articles or product categories.By mastering the use of this tag, users can easily build a well-structured and functional classification navigation on the front end, whether it is displayed by level or filtered according to the content model (such as articles, products), they can do so with ease.

Get to knowcategoryListTag

categoryListThe main function of the tag is to obtain the preset category data from the AnqiCMS backend and display it in a list format on the front page. Its basic structure is as follows:

{% categoryList categories with ... %}
    {# 在这里循环输出分类信息 #}
{% endcategoryList %}

Here, categoriesis a custom variable name used to store data for each category when looping within a tag.withKeywords are followed by a series of parameters, used to control which categories to retrieve and how to filter and sort.

Core parameter parsing: Fine-grained control of category display

categoryListThe power of tags lies in their rich parameter options, which allow you to filter and organize classification information flexibly according to your actual needs.

  1. Filter by content model (moduleId)AnqiCMS is characterized by its flexible content model.Each category must belong to a specific content model, such as "article model" or "product model".When you want to display a specific type of content category,moduleIdThe parameters come into play.

    • To display all categories under the "Article Model", usually set tomoduleId="1".
    • To display all categories under the "Product Model", usually set tomoduleId="2"。(The specific model ID can be found in the AnqiCMS backend under "Content Management" -> "Content Model".)

    For example, if you only want to list all product categories:

    {% categoryList productCategories with moduleId="2" %}
        {# 循环输出产品分类 #}
    {% endcategoryList %}
    
  2. Build a hierarchical structure (parentId)Website navigation is often multi-level,parentIdThe parameter is designed to meet this need.

    • Display top-level categories:settingparentId="0"Only the top-level categories under the specified content model will be obtained.
    • Show the subcategories of the current category:In the category list page or detail page, if you want to display all direct subcategories of the current category, you can omitparentIdThe parameter, the system will automatically identify the current category ID and get its subcategories.
    • Show the sibling categories of the current category:If you want to display all categories at the same level on a category page (i.e., sibling categories), you canparentIdis set toparentId="parent"This is usually used in the content list page combined with the current category.

    For example, to display all top-level categories of articles:

    {% categoryList topArticleCategories with moduleId="1" parentId="0" %}
        {# 循环输出文章顶级分类 #}
    {% endcategoryList %}
    
  3. Get all categories (all)In certain specific scenarios, you may need to list all categories under a model without considering their hierarchical relationships, such as in the background management interface or when building a complete website map. At this point, you canallthe parameter totrue.

    {% categoryList allCategories with moduleId="1" all=true %}
        {# 循环输出所有文章分类,不分层级 #}
    {% endcategoryList %}
    
  4. Control the display quantity (limit)If you only want to display a fixed number of categories, you can uselimita parameter to limit the number of returned entries. For examplelimit="10"only the first 10 categories will be displayed. You can also useoffsetpattern, such aslimit="2,10"Starting from the second category, retrieve 10 categories.

  5. Multi-site compatibility (siteId)AnqiCMS supports multi-site management. If you have deployed multiple sites and want to call data from a specific site, you can do so bysiteIdSpecify the site ID with the parameter. Generally, if you only manage one site, this parameter does not need to be set.

Get and display category information:itemVariable Details

IncategoryListEach in the loop inside the tag,itemVariables contain detailed information about the current category, you can call and display them as needed:

  • {{ item.Id }}Unique ID of the category.
  • {{ item.Title }}: The display name of the category.
  • {{ item.Link }}: The access link of the category page, AnqiCMS will automatically generate according to the pseudo-static rules.
  • {{ item.Description }}: The introduction or description of the category.
  • {{ item.ParentId }}: The parent category ID of the current category.
  • {{ item.HasChildren }}A boolean value indicating whether the current category contains subcategories. This is very useful for building dynamic nested navigation.
  • {{ item.Spacer|safe }}A very useful field that automatically generates indentation or prefix based on the level of the category, making it easy to display the hierarchy in a list (for example:├─/└─Remember to use|safeFilter to ensure correct rendering of HTML characters.
  • {{ item.Logo }}and{{ item.Thumb }}: The address of the large image and thumbnail of the category.
  • {{ item.ArchiveCount }}: The total number of documents under the category (including subcategories).

Practice: Build Flexible Category Navigation

Now, let's demonstrate through several practical scenarioscategoryListFlexible use of tags.

Scenario One: Display Top Categories Under Specific Content Model

Assuming we need to display all top-level categories under the "Article Model" on the homepage as part of the main navigation.

<nav class="main-nav">
    <ul class="category-list-top">
        {% categoryList articleCategories with moduleId="1" parentId="0" %}
            {% for category in articleCategories %}
                <li><a href="{{ category.Link }}">{{ category.Title }}</a></li>
            {% endfor %}
        {% else %}
            <li>暂无文章分类</li>
        {% endcategoryList %}
    </ul>
</nav>

This code will filter outmoduleIdWith1(Article Model) andparentIdWith0All categories of the top-level classification, displayed in an unordered list with names and links.

Scenario two: Building multi-level nested category navigation

The more common requirement is to build a navigation menu with a multi-level structure, such as having multiple product series under "Product Center", and each series having specific product types. In this case, nested menus can be used.categoryListand tags to combineHasChildrenProperty.

`twig

<h3>产品分类</h3>
{% categoryList productCategories with moduleId="2" parentId="0" %}
    <ul class="level-1-categories">
        {% for category in productCategories %}
            <li {% if category.HasChildren %}class="has-submenu"{% endif %}>
                <a href="{{ category.Link }}">{{ category.Title }}</a>
                {% if category.HasChildren %}
                    {# 递归调用子分类,AnqiCMS模板引擎可以很好地

Related articles

How to implement breadcrumb navigation in AnqiCMS templates and control the display of the home page name and document title?

In website operation, a clear navigation path is crucial for user experience and search engine optimization (SEO).Breadcrumb Navigation as an auxiliary navigation method can directly tell users where the current page is in the website structure, effectively reduce the bounce rate, and help search engines better understand the website hierarchy.

2025-11-09

How to build and display the AnqiCMS multi-level website navigation list, and support custom styles and subtitle display?

Building an efficient, intuitive, and user-friendly website depends on carefully designed navigation systems.In AnQiCMS, building a multi-level website navigation list, and supporting custom styles and subtitle display, is a powerful and flexible feature.It allows content operators to easily create menu structures that adapt to various complex scenarios according to business needs.

2025-11-09

How to customize the homepage title, keywords, and description through AnqiCMS's TDK tags to improve search engine display?

In website operation, it is crucial to have your website displayed better in search engines, and the TDK (Title, Description, Keywords) tags on the homepage are the core to achieve this goal.AnqiCMS as a SEO-friendly content management system provides intuitive and powerful features to help you easily customize these key elements.By cleverly setting the homepage TDK, you can not only improve the visibility of the website in the search results, but also attract more target users to click and visit.### Understand TDK

2025-11-09

How to display the contact information set in the AnqiCMS backend on the front page and support custom parameter display?

A website can effectively convey information, one of the core elements being that visitors can easily find the contact information.Whether it is in the footer of the website, a special "Contact Us" page, or in the article content, clear and clear contact information is the key to improving user experience and building trust.AnqiCMS (AnqiCMS) with its flexible and customizable features allows you to easily manage this information in the background and display it on the front page, even supporting custom parameters to meet various business needs.Next, let's take a look at how to use the AnqiCMS website front page on your site

2025-11-09

How to accurately call and display the detailed information of a specific category in AnqiCMS on the front page, including the description and Banner image?

In AnqiCMS (AnqiCMS), the need to accurately call and display detailed information about a specific category on the front page, such as the category description and its exclusive Banner image, is a common requirement.This can make the structure of the website content clearer, as well as improve user experience and the website's SEO performance.Benefiting from AnqiCMS flexible template tag system, achieving this goal is actually very direct. We mainly use a core template tag——`categoryDetail`.

2025-11-09

How to use AnqiCMS's single page list tag to flexibly display independent pages such as 'About Us' on the front end?

In modern website operations, pages like "About Us", "Contact Information", and "Terms of Service" are independent pages that carry the basic information and brand image of the website. Although they are not updated often, they are crucial.AnqiCMS provides a flexible single-page management feature, combining its powerful template tag system, we can easily display these independent pages on the front end and customize them as needed.

2025-11-09

How to call and display the detailed content and images of a specific page in AnqiCMS on the front page?

In AnQiCMS, it is actually much simpler than you imagine to call and display the detailed content and images of a specific single page on the front page.AnQiCMS's powerful template tag system, especially the tags designed for single-page layouts, can help you achieve this easily. ### Understanding AnQiCMS Single Page Functionality Firstly, we know that AnQiCMS provides an independent "Page Management" module that allows us to create independent single pages such as "About Us", "Contact Information", or "Service Introduction".This page's content, images, SEO information, etc.

2025-11-09

How to use AnqiCMS document list tags to display the latest, hot, or specified category of articles/products on the front page?

In AnqiCMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether you want to highlight the latest articles on the homepage, display popular products in the sidebar, or customize content lists for specific columns, AnqiCMS's powerful document list tags can help you a lot.By skillfully using these tags, you can easily achieve a diverse presentation of content, making your website more dynamic and attractive.### Core Tag: `archiveList`

2025-11-09