In AnQiCMS, effective management and display of website categories are the key to improving user experience and content organization.Whether it is to build a navigation menu, sidebar content, or display the category structure on a specific page, it is a common requirement to flexibly obtain the name, description, link, and subordinate category list of the category.This article will introduce how to use AnQiCMS template tags to easily achieve these functions.


Flexibly obtain and display information of specified categories and subcategory lists

The clear classification of website content is not only convenient for users to browse, but also greatly benefits search engine optimization (SEO).AnQiCMS's powerful template system provides us with intuitive and easy-to-use tags, which can accurately obtain and display the required classification data.To implement obtaining detailed information of a specified category and its subcategory list, we mainly use two core template tags:categoryDetailandcategoryList.

Core Tool:categoryDetailwithcategoryList

categoryDetailTags, as the name implies, are used to obtaina singleSpecify the details of a category. It can help us extract various attributes such as the title, description, link, etc. of a specific category. AndcategoryListThe tag focuses on obtaininga set ofA list of categories, very suitable for listing all subcategories under a parent category, or all top-level categories under a specific content model.Understand and properly apply these tags, it is the key to achieving our goals.

Get detailed information of a specified category

Firstly, we may need to get the basic information of a specific category, such as its name, description, and link. At this point,categoryDetailTags are our ideal choice. It allows us to specify the target category accurately through the unique ID of the category (id) or URL alias (token) to specify the target category precisely.

For example, if you have an ID on your website of5The classification, and if you want to display its title, description, and link on the page, you can write the template code like this:

{# 假设要获取ID为5的分类的详细信息 #}
{% categoryDetail myCategory with id="5" %}
<section class="category-detail-section">
    <h1>分类名称:{{ myCategory.Title }}</h1>
    <p>分类描述:{{ myCategory.Description }}</p>
    <a href="{{ myCategory.Link }}">前往{{ myCategory.Title }}分类页面</a>
</section>

In this code, we will use the ID of5Retrieve the classification information and assign it tomyCategoryvariable. Subsequently, we can easily access and display the name, description, and link of the classification throughmyCategory.Title/myCategory.DescriptionandmyCategory.Linkproperties.categoryDetailTags also provide other rich fields, such asContent(Rich text content of the category),Logo(Category Large Image),Thumb(Category thumbnail) and more, you can flexibly call them as needed.

Display the list of subcategories under the specified category.

After obtaining the detailed information of a specified category, the next step is usually to display all the subcategories under the category. At this point,categoryListthe tag shines brightly on stage.categoryListByparentIdParameters to specify which parent category's subcategories we want to retrieve.

Continuing with the above example, if we want to list the category with ID5Category (i.e.myCategoryThe direct subcategories of ) can be operated in this way:

<section class="sub-categories-list">
    <h2>{{ myCategory.Title }}的子分类</h2>
    <ul>
        {% categoryList subCategories with parentId=myCategory.Id %}
        {% for subItem in subCategories %}
        <li>
            <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
        </li>
        {% endfor %}
        {% endcategoryList %}
    </ul>
</section>

Here, categoryListThe label's `