How to extend the additional features of the `categoryList` tag without modifying the AnQiCMS core code?

Calendar 👁️ 64

As an experienced website operations expert, I know how to skillfully utilize the existing functions of the CMS system without touching the core code, which is crucial for maintaining system stability and reducing upgrade costs. AnQiCMS (AnQiCMS) relies on its flexible template engine and rich tag system to provide us with a powerful tool for deep customization at the content operation level, among whichcategoryListTags are often a point where we need to extend functionality.

In AnQi CMS,categoryListThe tag is used to retrieve the classification list of the website, which can help us build navigation, display classification entries, or aggregate content under specific categories.However, in actual operation, we may wish for these classification lists to carry more information, or to be displayed in a more intelligent way, rather than simply being simple classification names and links.Next, I will focus on how to expand without modifying the core code of AnQiCMScategoryListTags' additional features, a detailed explanation of several effective strategies.

Deep understandingcategoryListTags' basic capabilities

First, let's reviewcategoryListThe power of tags. It allows us tomoduleIdspecify content models (such as article models, product models), toparentIdfilter child categories under specific parent categories, even toall=trueGet all categories. When iterating over the tag results, each category item (item) comes with rich properties such asId(Category ID),TitleCategory Title,Link(Category link),Description(Category Description),Logo(Category thumbnail large image),Thumb(Category Thumbnail),HasChildren(whether there are subcategories) andArchiveCount(The number of documents under the category) and others. These built-in properties are the foundation for our functional expansion.

However, when built-in properties fail to meet our personalized needs, we need to seek additional extension methods.Fortunately, AnQiCMS has left us ample room for maneuver, allowing us to enhance the functionality at the template level without touching the core code of the Go language.

The extension philosophy of AnQi CMS: not touching the core code

AnQiCMS advocates a "decoupling" development concept, separating the core business logic from the front-end display logic.This means that even if we need to customize complex functions, we can often find solutions at levels such as template files, custom fields, auxiliary tags, and filters.This method not only ensures the smoothness of system upgrades, but also greatly reduces the threshold and risk of secondary development.

Actual combat practice: extensioncategoryListSeveral practical methods

Method one: cleverly use custom fields to add dimensions to classification information

In many cases, we want to add some non-standard attributes to each category, such as a unique icon, a catchy slogan, or additional images related to the category.The content model management function of AnQiCMS allows us to customize fields for categories, which is the first step to meet this requirement.

Operation steps:

  1. Add custom fields to the classification model in the background:Navigate to "Content Management" -> "Content Model", select the model you want to expand the category to (for example, "Article Model").After entering the model editing interface, you can find the "content model custom field" area.Here, you can add new fields such as "category icon" (icon)、“Background Image”(bannerImage) and so on.

    • Field type selection:Select the appropriate field type based on your needs, for example, 'Single line text' is used to store the URL or CSS class name of the icon, and the 'Image' type is used to store the background image.
    • Field naming call:Make sure to set an easily identifiable 'call field' name for your custom field, for examplecategory_icon/category_banner.
  2. Fill in the custom field content on the category editing page:When creating or editing a specific category, you will see the custom field you just added. Enter the corresponding content for each category.

Call the custom field in the template:

Once the custom fields are set up, we can incategoryListin the loop, pass through directlyitem.你的自定义字段名to access these new properties.

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <li class="category-item">
            <a href="{{ item.Link }}" title="{{ item.Title }}">
                {# 调用自定义字段:分类图标 #}
                {% if item.category_icon %}
                    <i class="{{ item.category_icon }}"></i>
                {% endif %}
                <h3>{{ item.Title }}</h3>
                <p>{{ item.Description|truncatechars:50 }}</p>
                {# 调用自定义字段:背景图片 #}
                {% if item.category_banner %}
                    <div class="category-banner" style="background-image: url('{{ item.category_banner }}');"></div>
                {% endif %}
            </a>
            {# 还可以根据HasChildren判断是否显示子分类,并调用子分类列表 #}
            {% if item.HasChildren %}
                <ul class="sub-categories">
                    {% categoryList subCats with parentId=item.Id %}
                        {% for subItem in subCats %}
                            <li><a href="{{ subItem.Link }}">{{ subItem.Title }}</a></li>
                        {% endfor %}
                    {% endcategoryList %}
                </ul>
            {% endif %}
        </li>
    {% empty %}
        <p>暂无分类信息。</p>
    {% endfor %}
{% endcategoryList %}

In this way, we add unique visual elements and additional information to each category without touching any Go language code in AnQiCMS.

Method two: Use template logic and filters to process list data as needed

AnQiCMS template engine supports conditional judgment (if)、looping over(for) and a rich set of filters (filters)。These tools are enough to allow us to perform complex data processing and display logic at the template level.

1. Conditional rendering and filtering:We may need to decide how to render it based on some properties of the category. For example, only display categories with documents, or apply special styling to categories with specific IDs.

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        {# 只显示文档数量大于0的分类 #}
        {% if item.ArchiveCount > 0 %}
            <li class="category-item {% if item.Id == 10 %}highlight{% endif %}">
                <a href="{{ item.Link }}">
                    <h4>{{ item.Title|upper }}</h4> {# 将分类标题转换为大写 #}
                    <p>{{ item.Description|truncatechars:80 }}</p> {# 截取描述文字 #}
                    <span>包含文档:{{ item.ArchiveCount }} 篇</span>
                </a>
            </li>
        {% endif %}
    {% empty %}
        <p>暂无分类信息。</p>
    {% endfor %}
{% endcategoryList %}

We used hereitem.ArchiveCountPerform conditional judgment and combineitem.IdAdd specific styles. At the same time, useupperThe filter converts the title to uppercase,truncatecharsThe filter truncates the description content, making it more concise.

2. Data Combination and Linkage:IncategoryListIn the loop, we can nest other tags to achieve linkage between different data. For example, under each category, display the latest several documents.

`twig {% categoryList categories with moduleId=“1” parentId=“0” %}

{% for item in categories %}
    <div class="category-block">
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <ul class="latest-archives">
            {# 在每个分类下,调用该分类最新的5篇文档 #}
            {% archiveList archives with type="list" categoryId

Related articles

Does the `categoryList` tag support fuzzy search or filtering by category name (without going through URL parameters)?

As an experienced website operation expert, with a deep understanding of the various functions and content operation strategies of AnQiCMS, I am more than happy to analyze whether the `categoryList` tag in AnQiCMS supports fuzzy search or filtering based on category names, an important issue.In the Anqi CMS template system, the `categoryList` tag is the core tool for developers and content operators to obtain and display the website category list.It helps us build clear website navigation and content structure with its concise and efficient characteristics. However,

2025-11-06

In AnQiCMS, `categoryList` and `pageList` coexist without any issues, a practical template for intelligent operation

As an experienced website operations expert, I know that the flexible use of template tags in a content management system is the key to building an efficient and multifunctional website.Many AnQiCMS (AnQiCMS) users, especially those friends who are new to template development, may have a question: Will there be a conflict if tags with different functions like `categoryList` and `pageList` are used simultaneously on the same page??

2025-11-06

How to ensure that the `categoryList` generates absolute path links for external reference or SEO?

As an expert who deeply understands website operation, I know the importance of the standardization of website links for search engine optimization (SEO) and user experience.In such an efficient and powerful content management system as AnqiCMS, ensure that category links are presented in absolute path form, which not only enhances the visibility of the website in search engines but also facilitates the citation and sharing of content on external platforms.Today, let's delve into how to elegantly achieve this goal in AnqiCMS.### The Foundation for Optimizing SEO and External References: Understanding the Value of Absolute Paths Imagine that

2025-11-06

`categoryList`is there a difference or**practice**in the way it is called in the mobile template and PC template?

As an experienced website operations expert, I am well-versed in the powerful functions and essence of content operation of AnQi CMS, and I am delighted to delve into the calling method of the `categoryList` tag in the mobile and PC templates of AnQi CMS, as well as how to use its features to achieve efficient and user-friendly content presentation.On a day when content marketing and user experience are increasingly important, the performance of a website on different devices is crucial.AnQi CMS understands this, as can be seen from its project advantages and core features, it provides "adaptive, code adaptation"}

2025-11-06

Is the HTML structure generated by `categoryList` friendly to search engine crawlers, and how can it be optimized?

As an experienced website operations expert, I know that every detail can affect the performance of a website in search engines.Today, let's delve deeply into the `categoryList` tag generated by AnQiCMS, the degree of friendliness of its HTML structure to search engine spiders, and how we can cleverly optimize it to improve the website's SEO performance.Since its inception, AnQi CMS has been favored by operators for its SEO-friendly design concept.

2025-11-06

How to handle the pagination problem when nesting `archiveList` inside `categoryList`?

As an experienced website operations expert, I have accumulated rich experience in the content management practice of AnQiCMS.I am well aware that when facing the powerful template tag system of AnQiCMS, how to skillfully combine them to achieve the expected content display effect is a challenge that many operators and developers will encounter.Today, let's delve into a common yet confusing issue: how to properly handle the pagination problem of `archiveList` when nesting `categoryList`?

2025-11-06

`categoryList` returns the category data whether it includes user group or permission-related setting information?

In the daily operation and template development of AnQi CMS, we often need to obtain site data from different angles, and the category list (`categoryList`) is undoubtedly one of the most commonly used tags.However, regarding whether the `categoryList` returned classification data includes user group or permission-related setting information?This topic, we delve into the design philosophy and functional implementation of AnqiCMS, revealing the logic behind it.

2025-11-06

How to truncate long category names in the `categoryList` loop and add an ellipsis?

## Enterprise CMS Template Tips: Gracefully truncate long category names and add ellipsis In website operation, the display of category names may seem trivial, but it actually has a significant impact on user experience and page aesthetics.A well-designed website ensures that all its elements can coexist harmoniously, especially the navigation and text in the list.When the category name is too long, it may cause layout confusion, text overflow, and even poor display on different devices, seriously affecting the user's reading experience

2025-11-06