How does the `categoryDetail` tag help us retrieve and display detailed information for a specific category?

Calendar 👁️ 70

AnQiCMS (AnQiCMS) provides powerful and flexible tools for website content management, includingcategoryDetailTags play a very important role in building a website that is rich in content and clear in structure.It can help us accurately obtain and display detailed information about a specific category, whether it is used for the header introduction on the category list page or to display more content about the category on the article detail page, it is very convenient.

categoryDetailBasic usage of tags

In simple terms,categoryDetailThe label's function is to "get detailed information about a category".This is similar to the logic of obtaining article details or single-page details, it allows us to specify a category, then extract the title, description, link, image, and all related data of the category, and display them on the website front end.

Typical application scenarios of this tag include:

  • Display the current category title, SEO description, and image at the top of the category list page.
  • Show the category name and link on the article or product detail page, for easy user navigation.
  • In the sidebar or footer navigation of the website, dynamically display information for specific categories.

How to usecategoryDetailTag

categoryDetailThe basic syntax structure of the tag is:{% categoryDetail 变量名称 with name="字段名称" %}.

  • 变量名称This is an optional parameter. If we need to further process the obtained category information in the template, or want to assign the entire category object to a variable, then we can define a variable name.If you do not need to handle it specially, you can also omit the variable name when directly outputting the value of a field.
  • name="字段名称": This is the most core parameter, it tells the tag which specific field of the category we need to obtain. For example,name="Title"Will retrieve the category title,name="Description"Will retrieve the category description.

In addition to specifying the fields to be retrieved, we can also use other parameters to clarify which category it is:

  • id="分类ID"Through specifying the numeric ID of the category, you can obtain its details. This is the most direct and commonly used method. If not specifiedid,categoryDetailThe tag will default to trying to obtain the information of the category the current page belongs to.
  • token="分类URL别名"If the category is set to a custom URL alias (usually English or pinyin), you can also specify the category through this alias.
  • siteId="站点ID"In the multi-site management scenario of AnQiCMS, if you need to obtain the category information of other sites, you can throughsiteIdSpecify the target site with parameters

Common fields and their application examples

categoryDetailThe tag can retrieve various information about the category, and below are some commonly used fields and their application in the template:

  1. Category ID (Id) and category title (Title)This is the most basic classification information, often used to display classification names or as a basis for internal logic judgments.

    <!-- 获取当前页面的分类ID -->
    <div>当前分类ID:{% categoryDetail with name="Id" %}</div>
    <!-- 获取ID为5的分类标题 -->
    <div>特定分类标题:{% categoryDetail with name="Title" id="5" %}</div>
    
  2. Category link (Link)Used to generate a category page jump link, ensuring that users can click to visit the detailed content of the category.

    <!-- 创建一个指向当前分类的链接 -->
    <a href="{% categoryDetail with name="Link" %}">
        {% categoryDetail with name="Title" %}
    </a>
    
  3. Category description (Description) and category content (Content) DescriptionIt is usually used for SEO optimization or a brief category introduction, whileContentit is used to display the main content of the category page. IfContentThe field contains Markdown formatted content, and the background has enabled Markdown editor, which will automatically render it as HTML; if you want to manually control the rendering behavior, you can userenderparameters, for examplename="Content" render=true.

    <!-- 显示分类的SEO描述 -->
    <meta name="description" content="{% categoryDetail with name="Description" %}">
    <!-- 显示分类页面的主体内容,并确保HTML安全渲染 -->
    <div class="category-content">
        {% categoryDetail categoryFullContent with name="Content" %}
        {{ categoryFullContent|safe }}
    </div>
    
  4. Parent category ID (ParentId)When building a multi-level category navigation or breadcrumb navigation, this field is very useful, as it can be used to determine the hierarchy of the current category.

    <!-- 获取当前分类的上级分类ID -->
    {% categoryDetail currentCategoryParentId with name="ParentId" %}
    {% if currentCategoryParentId > 0 %}
        <div>上级分类ID:{{ currentCategoryParentId }}</div>
    {% endif %}
    
  5. Category thumbnail (Thumb) and category large image/Logo (Logo)Categorization images are usually used for displaying category lists or as the top banner image on category pages.LogoIt usually refers to the original or larger image,Thumbwhich is a thumbnail processed by the system.

    <!-- 在分类列表或详情页显示分类缩略图 -->
    <img src="{% categoryDetail with name="Thumb" %}" alt="{% categoryDetail with name="Title" %}">
    
  6. Category Banner group image (Images)This field is very suitable for displaying a carousel or multiple promotional images at the top of the category page. It should be noted that,ImagesIt returns an array of image URLs, so it needs to be配合forLoop to traverse and display.

    {% categoryDetail categoryBanners with name="Images" %}
    {% if categoryBanners %}
        <div class="category-banner-slider">
            {% for imageUrl in categoryBanners %}
                <img src="{{ imageUrl }}" alt="分类横幅">
            {% endfor %}
        </div>
    {% endif %}
    
  7. Number of categorized documents (ArchiveCount)You can display how many articles or products are under the category name next to it, improving the information volume and user experience.

    <h3>
        <a href="{% categoryDetail with name="Link" %}">
            {% categoryDetail with name="Title" %} (共{% categoryDetail with name="ArchiveCount" %}篇文章)
        </a>
    </h3>
    
  8. Custom fieldIf we set custom fields for categories in the content model of the backend, these fields can also be accessed throughcategoryDetailtags. You can access them directly throughname="你的自定义字段名"this method.

    <!-- 如果有一个名为 "category_slogan" 的自定义字段 -->
    <p>分类口号:{% categoryDetail with name="category_slogan" %}</p>
    
    <!-- 遍历所有自定义字段 -->
    {% categoryDetail extras with name="Extra" %}
    {% for field in extras %}
        <div>{{ field.Name }}:{{ field.Value }}</div>
    {% endfor %}
    

Summary

categoryDetailTags are an indispensable part of AnQiCMS template development, making it intuitive and efficient to obtain and display classification information.By flexibly utilizing the various parameters and fields it provides, we can easily build dynamic, user-friendly category pages, thereby effectively enhancing the organization and SEO performance of the website's content.Whether it is a simple title display, or a complex picture carousel and custom field display,categoryDetailAll of them can provide strong support.

Frequently Asked Questions (FAQ)

1. Why mycategoryDetailThe label does not display any content?

The most common reason is that you have not specifiedidortokenOr the current page is not associated with any category, causing the tag to be unable to automatically identify the category to be retrieved.Make sure to specify the category ID or alias you want to use when operating, or use it on the category page so that it can automatically obtain information about the current category.Also, also checknameIs the parameter spelled correctly, and does the category indeed exist for the field data you are trying to retrieve?

2. How tocategoryDetailHow to get all custom fields of a specific category instead of writing them out one by one?

You can usename="Extra"To get an array containing all custom fields. Then, you can go throughforLoop through this array to display the names and values of each custom field. For example:{% categoryDetail extras with name="Extra" %}{% for field in extras %} <div>{{ field.Name }}:{{ field.Value }}</div>{% endfor %}.

3.LogoandThumbWhat are the differences between the fields? Which one should I use?

LogoIt usually refers to the original or larger-sized images used for the main visual or large banners on category pages.ThumbIt is usually a small thumbnail image automatically generated by the system according to preset rules, suitable for category lists, card displays, or where page loading resources need to be saved. You should choose to use it according to your design requirements and the use scenario of the image.LogoOrThumb.

Related articles

How to use the `archiveList` tag to display document lists on different page types (such as lists, pagination, related documents)?

AnQi CMS provides strong support for website operators with its efficient and flexible content management capabilities.Among many practical features, the `archiveList` tag plays a core role, and it is a powerful tool for displaying various document lists on your website's front end.No matter if you want to display the latest articles on the homepage, present specific content on the category page, or recommend relevant information on the detail page, `archiveList` can help you achieve it with concise syntax.By reasonably configuring the `archiveList` tag parameters, you can easily master the way content is presented

2025-11-08

How to use the `archiveDetail` tag in AnQiCMS template to retrieve and display detailed information of a single document?

Under the powerful support of Anqi CMS, we can flexibly build various types of website content.Among them, displaying the detailed information of a single document is one of the core needs of website content display.AnQi CMS provides a special template tag——`archiveDetail`, which can help us easily obtain and present all relevant data of the document in the template.Using the `archiveDetail` tag, even users who are not very familiar with template language can quickly get started and transform technical information into a smooth reading experience on the website.##

2025-11-08

How to configure content settings to automatically handle remote image downloads, external link filtering, and Webp image format conversion to optimize display performance?

The efficiency of content presentation and user experience is one of the key factors for success.In the daily operation, the speed of image loading, the standardization of links, and other details all directly affect the visitors' stay and the search engine's friendliness.AnQiCMS is well-versed in this, providing a variety of practical functions in content settings to help us easily cope with these challenges and optimize the display performance of the website. ### Automatically Handle Remote Image Downloads: Make Content More Stable and Load Faster When editing website content, we sometimes refer to images from other websites.

2025-11-08

How does the AnQi CMS scheduled publication function control content to be displayed to the public after a specified time?

In today's world where digital content is increasingly abundant, an efficient and accurate content publishing strategy is crucial for any website operator.AnQiCMS (AnQiCMS) understands this and has specially provided you with a powerful timed publishing function, allowing you to precisely control when each piece of content is displayed to the public after the specified time, thus achieving more flexible and strategic content operation.

2025-11-08

How to use the `categoryList` tag to build a multi-level category navigation and control its display level?

The website's navigation system is like a map, guiding visitors smoothly to their destination.A well-organized, layered classification navigation that can significantly improve the user's browsing experience and also help search engines understand and index your website content more efficiently.In AnQi CMS, the `categoryList` tag is the tool to build a high-efficiency and flexible category navigation system.With it, you can easily display the website's category structure, even fine-tune the display level of each category.### `categoryList` Label Overview

2025-11-08

What are the applications of the `pageDetail` and `pageList` tags in displaying single-page content and list presentation?

When using AnQiCMS to build a website, the display of single-page content and page lists is an indispensable part.Whether it is an independent content page like "About Us" or a series of links in the website footer navigation, they all need flexible and efficient ways to manage and present.In AnQiCMS, the `pageDetail` and `pageList` tags are powerful tools designed to meet these needs.They each focus on different application scenarios and yet complement each other

2025-11-08

How to use the `tagDetail` and `tagDataList` tags to display information about a specific tab page and its associated documents?

AnQiCMS (AnQiCMS) is a flexible and efficient content management tool trusted by many operators.It is crucial to effectively present content classification and organization methods when building a functional and user-friendly website.Especially for the need to associate different content through "tags", mastering the use of the `tagDetail` and `tagDataList` template tags can make your website's tag page not only beautiful but also informative, greatly enhancing user experience and search engine optimization (SEO) effects.

2025-11-08

How to implement the `navList` tag for flexible display of top, bottom, or sidebar navigation menus on a website?

The website navigation is a guide for users to explore the website content and is also an important clue for search engines to understand the website structure.A well-designed, flexible navigation system that can greatly enhance user experience and website SEO performance.In AnQiCMS, the `navList` tag is just such a core tool that gives us great freedom, allowing us to easily build and manage navigation menus at various positions such as the top, bottom, and sidebars of the website.

2025-11-08