AnQi CMS is an efficient and customizable content management system that plays an important role in website operations.Its template system is powerful and flexible, allowing operators to finely control the display method of content according to actual needs.categoryListIn the tag, skillfully display "brother categories of the current category" instead of its subcategories.

It is of great significance to show the brother category list in terms of content organization and user experience.It can help users quickly find other related categories at the same level when browsing content in a certain category, thus promoting content discovery, improving the quality of internal links on the website, and ultimately optimizing SEO performance.

Deep understandingcategoryListThe flexibility of the tag

Anqi CMS'scategoryListTags are the core tools you use to call category data in templates. They provide a rich set of parameters, allowing you to precisely filter and display the required category information. Typically, we use them to:

  • Get the top-level category: By settingparentId="0", you can easily list all top-level categories that do not belong to any parent category.
  • Get the child categories under a specified parent category: By specifying a specificparentId="某个分类ID"You can get all direct subcategories under this ID.
  • Get all categories: When you need to display the entire category tree, you can setall=trueand combinemoduleIdto get all categories under a specific model.

However, the focus of our discussion today is on how to transcend these common usages and achieve precise acquisition of the 'brother category'.

Achieving the list of 'brother categories' of the current category:parentId="parent"The mystery of

The designer of AnQi CMS clearly considered this operational scenario and categoryListreserved a very concise and powerful parameter value in the tag:parentId="parent".

When you use tags on the category details page (or any page that can identify the current category context)categoryListwillparentIdparameter settings"parent"The system will automatically recognize the parent category of the current classification, and then list all classifications that belong to the same parent category as the current one. This is what we call 'sibling classifications'.

It is worth mentioning that this mechanism is very intelligent, as it eliminates the繁琐 steps of manually obtaining the parent ID of the current category, and then querying the child categories (excluding the current category itself) using the parent ID.It directly completes this logic for you.

Let us demonstrate through a specific example how to implement:

Suppose we are designing a name called文章The model's category details page (for example, the user is browsing the 'Product Introduction' category), and we hope to display other categories at the same level as 'Product Introduction' in the sidebar, such as 'Company News', 'Industry Dynamics', etc.

{# 首先,确保我们能获取到当前分类的详细信息。
   在分类详情页,通常系统会自动提供当前分类的上下文,
   或者我们可以使用 categoryDetail 标签明确获取。 #}
{% categoryDetail currentCategory with name="Id" %}
{# currentCategory 变量现在存储了当前分类的完整数据,包括其ID、父ID等 #}

<div class="sibling-categories">
    <h3>同级分类</h3>
    <ul>
        {# 使用 categoryList 标签,关键是设置 parentId="parent" #}
        {# 并且为了确保只显示当前模型下的分类,最好加上 moduleId #}
        {% categoryList siblings with moduleId=currentCategory.ModuleId parentId="parent" %}
            {% for item in siblings %}
                {# 排除当前正在浏览的分类自身 #}
                {% if item.Id != currentCategory.Id %}
                    <li class="{% if item.IsCurrent %}active{% endif %}">
                        <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
                    </li>
                {% endif %}
            {% empty %}
                <li>暂无其他同级分类</li>
            {% endfor %}
        {% endcategoryList %}
    </ul>
</div>

In this code block:

  1. We first go through{% categoryDetail currentCategory with name="Id" %}[Here, only the ID is obtained as an example, actually]currentCategorymore fields will be included) to ensure we have the category context for the current page. Even on the category list page,currentCategoryVariables may also be automatically filled by the system.
  2. Next, we call{% categoryList siblings with moduleId=currentCategory.ModuleId parentId="parent" %}Here,moduleId=currentCategory.ModuleIdEnsure that we only retrieve sibling categories that belong to the same content model (such as "articles" or "products") as the current category, to avoid confusion.parentId="parent"This is the key instruction to implement the retrieval of sibling categories.
  3. InforInside the loop, we added a{% if item.Id != currentCategory.Id %}The condition judgment is to exclude the category the current user is visiting from the sibling list, to avoid duplication and provide clearer navigation.
  4. {% empty %}The label elegantly handles the situation when there are no other sibling categories to display, enhancing the user experience.

By making such a simple configuration, you can dynamically display the list of sibling categories on any category page of the website, greatly enhancing the website's navigation capabilities and user-friendliness.

Operation Tips

  • Sidebar navigation: Placing the sibling category list in the sidebar of the category page is an efficient way to guide users to discover more related content.
  • Supplement to breadcrumb navigationAlthough breadcrumbs mainly show the hierarchical relationship, the brother category list provides horizontal expansion, and the two complement each other.
  • Content relevanceThe brother category usually means a close relevance of content themes, which helps to enhance the relevance between pages, and is very beneficial for the internal link structure of SEO.

The template tag design of AnQi CMS aims to simplify complex logic,parentId="parent"The usage is an excellent demonstration of this concept. Mastering this skill will elevate your website operations to a higher level, and users will be able to navigate your website effortlessly.


Common Questions (FAQ)

Q1: If the current category is a top-level category (i.e., it has no parent), useparentId="parent"What will be displayed?

A1: When the category you are currently in is itself a top-level category, it does not have the concept of a 'parent', and therefore does not have 'sibling categories'. In this case,parentId="parent"No results will be returned,.categoryListIn the loop{% empty %}Part will be executed, you can set corresponding prompt information, such as 'No同级categories available' or 'You are currently at the top-level category'.

Q2: Can I get both sibling categories and child categories at the same time and display them in the same area?

A2: Yes, but you need to make two separate calls.categoryListLabel to get these two data. One time useparentId="parent"Get the sibling category, and the other time it can be omittedparentIdParameters (if the current page is a category page, it will default to fetching the subcategories of the current category), or explicitly specify the ID of the current category to fetch its subcategories.After that, you can merge and display them in the template, or place them separately in different visual areas.

Q3:categoryListthe tag inmoduleIdIs the parameter required here?

A3: Although the system may be able to intelligently judge in some page contextsmoduleId, it is strongly recommended to usecategoryListGet the specific type of category (such as article category, product category) and always specify it clearlymoduleIdParameters. This ensures that even in complex template structures, you can accurately obtain the classification data you expect, avoiding confusion between different content models. Typically,currentCategoryAn object will includeModuleIdfields, which can be directly referenced.