As an experienced CMS website operation personnel in information security, I know how crucial the flexibility of content organization and presentation is for attracting and retaining users.The site's classification structure is not only the skeleton of the content, but also an important path for users to explore and discover information.categoryListandcategoryDetailThey help us efficiently obtain and display category lists and detailed information of individual categories.

Flexible construction of category navigation:categoryListPractical application of tags

In the Anqi CMS,categoryListTags are a powerful tool for building various classification navigation and content aggregation modules.As an operations personnel, we understand that the clarity of website navigation and content organization is crucial for user experience and search engine optimization.categoryListAll of them can accurately pull the required categories.

UsecategoryListThe basic syntax of the label is:{% categoryList 变量名称 with 参数... %}...{% endcategoryList %}. Here, you can assign the obtained category list to a custom variable, for examplecategoriesThen, use a loop inside the tag to traverse these category data.

categoryListThe core parameters and their operational value

categoryListProvided with a variety of parameters, allowing you to finely control the classified data you obtain, which is particularly important in different operational scenarios:

  • moduleIdSpecify the content modelThis parameter allows you to explicitly specify the classification list of content models you wish to retrieve. For example, settingmoduleId="1"you can retrieve the classification of article models,moduleId="2"This may correspond to the product model. It is the key to keeping the content clear and separated when operating multiple content modules on a website (such as having both news information and product display).

  • parentIdEnglish: Control classification level parentIdThe parameter is the core of building分级navigation. When building the main navigation, we usually only need the top-level classification, and at this time, we need to setparentId="0"This can meet the requirements. And in the sidebar or dropdown menu, we may need to display the subcategories under a specific category, at which point we can do this by...parentIdSet the target category ID to easily achieve this. Even, when we need to display同级分类 on the same level in a specific category page,parentId="parent"The flexibility becomes apparent, it will automatically identify the parent category of the current classification and retrieve all sibling categories under it, which is very helpful for optimizing user experience and internal link structure.

  • allGet all categoriesWhen you need to get all categories at once, without considering their hierarchy or parent-child relationships, for example, on the website's category archive page or site map generation,all=trueIt will be very practical. If specified at the same time,moduleIdit will get all categories under the specified model.

  • limit: Limit the number of displayed items.On the homepage or sidebar and other locations, we often do not want to display too many categories to avoid information overload.limit="10"Such settings can help you control the number of displayed items. In addition, it also supportsoffsetMode, for examplelimit="2,10"It can start to get ten data from the third category, which is very flexible under some special layout requirements.

  • siteId: Data call for multiple sitesFor operators who manage multiple sites in the Anqi CMS,siteIdThe parameter is the key to implementing cross-site data calls. You can specifysiteIdto obtain classification data from other sites, which provides great convenience when building content alliances or sharing resources.

Traverse and display category data

When you go throughcategoryListGet the category list and assign it to a variable (for examplecategories) then you can usefora loop to traverse these categories, and useitemVariable access to each category's details.itemThe variable contains rich category fields, such as:

  • Id: The unique identifier ID of the category.
  • Title: The display name of the category.
  • Link: The access link of the category, which is the foundation for building navigation and content jump.
  • Description:Short description of the category, often used to enhance SEO effects or as supplementary navigation description.
  • Content:Detailed description content of the category.
  • ParentId:Parent ID of the category, used to determine the hierarchical relationship.
  • Logo/Thumb:Categorized images or thumbnails, which can be used for visual navigation or small banners on classification pages.
  • HasChildrenAn English translation of auto is English. The translated value is: A boolean value indicating whether the category has subcategories, which is very useful for dynamically generating menu structures.
  • ArchiveCountThe number of documents included in this category, which can be directly displayed to users to show the richness of the category content.

Code example: Build multi-level category navigation

The following example shows how to build a navigation with up to three levels, which is very practical for product categories of e-commerce websites or the column structure of information websites.

{% categoryList categories with moduleId="1" parentId="0" %}
{# 一级分类 #}
<ul>
    {% for item in categories %}
    <li>
        <a href="{{ item.Link }}">{{item.Title}}</a>
        <div>
            {% categoryList subCategories with parentId=item.Id %}
            {# 二级分类 #}
            <ul>
                {% for inner1 in subCategories %}
                <li>
                    <a href="{{ inner1.Link }}">{{inner1.Title}}</a>
                    <div>
                        {% categoryList subCategories2 with parentId=inner1.Id %}
                        {# 三级分类 #}
                        <ul>
                            {% for inner2 in subCategories2 %}
                            <li>
                                <a href="{{ inner2.Link }}">{{inner2.Title}}</a>
                            </li>
                            {% endfor %}
                        </ul>
                        {% endcategoryList %}
                    </div>
                </li>
                {% endfor %}
            </ul>
            {% endcategoryList %}
        </div>
    </li>
    {% endfor %}
</ul>
{% endcategoryList %}

This example uses nestedcategoryListLabel, which has implemented the display of multi-level classification.HasChildrenAlthough the field is not used directly here, it can help you determine whether you need to render the submenu in more complex dynamic menu logic.

Precisely present the details of classification:categoryDetailDetailed analysis of tags

When we want to display detailed information of a category page itself, or call the complete data of its category in a document detail page,categoryDetailThe tag is an indispensable tool. It helps us obtain all metadata for a single category, thus building a richer and more attractive category page.

categoryDetailThe basic usage of the label is:{% categoryDetail 变量名称 with name="字段名称" id="1" %}.categoryListSimilar to,nameYou can assign the obtained single category data to a variable, or directly obtain the value of a specific field through the

categoryDetailcore parameters.

categoryDetailThe parameter design focuses on obtaining details of a specific category:

  • idortoken: Precisely specify the categoryBy default, when you use this tag on the category page, it will automatically identify the current category. However, if you need to obtain information about other specific categories, you can specify theirid(category ID) ortokenThe URL alias can be used to call it accurately.tokenEspecially useful in pseudo-static URLs, you can directly obtain data through category aliases.

  • siteId: Data call for multiple sitesWithcategoryListThe same,siteIdThe parameter also supports calling the classification details of other sites in a multi-site environment.

Get and display the detailed information of the classification.

categoryDetailTags are mainly used fornameSpecify the classification fields to be retrieved. The available fields include:

  • Id/Title/Link/Description/ParentId/ArchiveCount:These fields are related tocategoryListofitemfields, used to obtain basic information, URL, and content statistics.
  • Content:Detailed content of the classificationThis field contains the rich text content you entered while editing categories in the background. It supports Markdown rendering, and if your category content is in Markdown format, you can set it byrender=trueConvert to HTML automatically.
  • Logo/Thumb: The cover image or thumbnail of the categoryThese two fields are usually used to display prominent images at the top of the category page, as a visual guide.LogoMay be used for a larger Banner image,Thumbwhich may be its thumbnail version.
  • **Images: Banner for categories