Category detail label `categoryDetail` how to get and display detailed information of a specific category?

Calendar 👁️ 76

In the website content operation of Anqi CMS, we often need to accurately obtain and display detailed information of specific categories. Whether it is to display the name, description, or related pictures and content of the category,categoryDetailTags can provide flexible and powerful support to help us build dynamic and rich classification pages.

categoryDetailCore functions and basic usage of tags

categoryDetailThe tag is used to obtain detailed data of a single category. Its basic structure is concise and clear, usually including the following parts:

{% categoryDetail 变量名称 with name="字段名称" id="分类ID" %}

  • Variable name (optional)You can specify a variable name for the category detail data you get, for examplemyCategoryThis is how you can refer to the data in subsequent template code. If you do not specify a variable name, the tag will directly output the value of the specified field.
  • name="字段名称"This is the most core parameter, used to specify the specific fields of the category data you want to obtain, such as the title of the categoryTitleDescription,Descriptionetc.
  • id="分类ID"(Optional)If you want to get the category information of a specific ID on the website, you can specify its ID here. If the current page itself is a category page (such as a category list page), and you want to get the details of the current category, then you can omit it.idparameter,categoryDetailThe label intelligently retrieves the category information of the current page.
  • token="分类URL别名"(Optional): withidsimilar,tokenThe parameter allows you to specify the category to be retrieved by using the category's URL alias. This is more intuitive in some cases than using the numeric ID.
  • siteId="站点ID"(Optional)For a CMS with multi-site functionality enabled, if you need to retrieve category data from a non-current site, you cansiteIdto specify the target site.

Common fields and their applications

categoryDetailTag throughnameParameters can access many properties of the category, here we list some commonly used fields and their application in the template.

1. Basic information of the category:Id,Title,Link,Description

These are the most basic and commonly used information categories, and the way to obtain them is very direct.

  • Category ID (Id):{% categoryDetail with name="Id" %}Or{{ category.Id }}(可以直接通过 category page)categoryobject access).
  • Category title (Title):{% categoryDetail with name="Title" %}Used to display category names.
  • Category link (Link):{% categoryDetail with name="Link" %}Used to build the jump link of the category.
  • Category description (Description):{% categoryDetail with name="Description" %}Used to display SEO description or brief introduction on the category page.

Example: Display category information at the top of the category page

<div class="category-header">
    <h1>{% categoryDetail with name="Title" %}</h1>
    <p>{% categoryDetail with name="Description" %}</p>
    <a href="{% categoryDetail with name="Link" %}" class="more-link">查看更多</a>
</div>

2. Category content (Content)

If your category has a dedicated introduction content (such as a detailed introduction for the "About Us" category), you can access it throughContentthe field. This field should pay special attention to its rendering method.

Example: Display the detailed content of the category

<div class="category-content">
    {% categoryDetail categoryMainContent with name="Content" %}
    {{ categoryMainContent|safe }}
</div>

Here|safeThe filter is crucial.The template engine of AnQi CMS defaults to escaping HTML content to prevent XSS attacks.|safeFilter. If the category content is written in Markdown, you can add byrender=trueParameters, let the system automatically convert it to HTML:

<div class="category-content">
    {% categoryDetail categoryMainContent with name="Content" render=true %}
    {{ categoryMainContent|safe }}
</div>

3. Category images:Logo,Thumb,Images

Category pages often need to display images, Anqi CMS provides a variety of image fields.

  • Category thumbnail large image (Logo)It is usually the main display image of the category.
  • Category thumbnail (Thumb): A thumbnail compressed or cropped by the system, suitable for use on list pages to improve loading speed.
  • Category Banner group image (Images)If the backend sets multiple Banner images for the category, this field will return an array of image URLs.

Example: Display the category Logo and Banner group images.

<div class="category-banner">
    <img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}">

    <h3>分类相册</h3>
    {% categoryDetail categoryBanners with name="Images" %}
    {% if categoryBanners %}
        <div class="image-gallery">
            {% for imgUrl in categoryBanners %}
                <img src="{{ imgUrl }}" alt="分类图片 - {% categoryDetail with name="Title" %}">
            {% endfor %}
        </div>
    {% endif %}
</div>

IfImagesIs a set of images, but you only need to display the first image as the cover, you can do it like this:

{% categoryDetail bannerImages with name="Images" %}
{% if bannerImages %}
    {% set firstBanner = bannerImages[0] %} {# 获取数组的第一个元素 #}
    <div class="page-banner" style="background-image: url({{ firstBanner }});">
        {# 其他内容 #}
    </div>
{% endif %}

4. Number of documents in the category (ArchiveCount)

This field is very useful, it can display how many articles or products are included in the current category.

Example: Display the number of articles in the category

<p>本分类共有 {% categoryDetail with name="ArchiveCount" %} 篇文章。</p>

5. Parent category ID (ParentId)

In a multi-level category structure, it is sometimes useful to obtain the parent category ID of the current category, for example, to build breadcrumb navigation or link to the parent category.

Example: Get and display the parent category ID

<p>当前分类的上级分类ID是:{% categoryDetail with name="ParentId" %}</p>

6. Custom Field

The strength of Anqi CMS lies in its flexible content model. If you add custom fields for the category model in the background,categoryDetailtags can also retrieve them.

Example: Retrieve and display all custom fields

<div class="category-custom-fields">
    {% categoryDetail extras with name="Extra" %}
    {% for field in extras %}
        <div>{{ field.Name }}:{{ field.Value }}</div>
    {% endfor %}
</div>

If you know the specific name of the custom field (for exampleauthor/price), you can also access it directly throughnameParameter retrieval:

<p>分类作者:{% categoryDetail with name="author" %}</p>
<p>分类价格区间:{% categoryDetail with name="price" %}</p>

Example of practical application scenarios

Assuming we have a 'News Dynamic' category list page, we want to display the name, description, thumbnail, and know how many articles it has on each news category card.

{# 假设我们正在循环显示顶级新闻分类 #}
{% categoryList newsCategories with moduleId="1" parentId="0" %}
    {% for categoryItem in newsCategories %}
    <div class="news-category-card">
        <a href="{{ categoryItem.Link }}">
            <img src="{% categoryDetail with name="Thumb" id=categoryItem.Id %}" alt="{{ categoryItem.Title }}">
            <h2>{{ categoryItem.Title }}</h2>
            <p>{{ categoryItem.Description|truncatechars:100 }}</p>
            <span>(共 {% categoryDetail with name="ArchiveCount" id=categoryItem.Id %} 篇文章)</span>
        </a>
    </div>
    {% endfor %}
{% endcategoryList %}

In this example, we are incategoryListthe loop, and throughcategoryDetailtags and pass the current loop item'sid(i.e.),categoryItem.Id), to get more detailed thumbnails and article counts for each category.

Summary

categoryDetailTags are an indispensable tool for obtaining and displaying category information in Anqi CMS template development.It provides a series of data interfaces ranging from basic titles, descriptions to complex content, image groups, custom fields, etc.name/id/tokenand parameters, as well asContentfield'srenderprocessing andImagestraversing arrays, we can easily build highly customized, information-rich category pages, greatly enhancing the presentation effect and user experience of website content.


Frequently Asked Questions (FAQ)

How do I get the details of a category on a non-category page?

Answer: On non-category pages (such as the home page, article detail page, or custom page), you can useidortokenSpecify the parameter to clearly specify which category details to retrieve. For example, if you want to display the description of the "About Us" category with ID 5 on the homepage, you can write it like this:{% categoryDetail with name="Description" id="5" %}.

**2. `categoryDetail

Related articles

Label for category list `categoryList` how to get and display article, product category information?

Manage and display website content in AnQiCMS, the classification information plays a vital role.Whether it is to organize product catalogs or organize article topics, a clear classification structure can greatly enhance user experience and the navigation efficiency of the website.And the `categoryList` tag is a powerful tool provided by AnQiCMS, helping us to flexibly obtain and display these category information.The `categoryList` tag is mainly used to retrieve and loop through the category data on your website.

2025-11-07

How to dynamically generate and display the current page's breadcrumb navigation path? breadcrumb

In website operation, a clear navigation path is crucial for user experience and search engine optimization.Imagine, when users browse your website, it's like exploring a strange city. If they can always see where they are and how they got there, it will greatly enhance their confidence and browsing efficiency.This is the value of breadcrumb navigation (Breadcrumb Navigation).It is like a trail of breadcrumbs in your hand, providing a clear path for users from the homepage to the current page.

2025-11-07

How to build and display the hierarchical navigation menu of the website's navigation list label `navList`?

In website operation, a clear and convenient navigation menu is the key to user experience, as well as an important basis for search engines to understand the website structure.AnQiCMS provides powerful navigation management features, and its template tag `navList` is the core tool for building these hierarchical navigation menus on the front end.

2025-11-07

How to generate and display personalized SEO titles, keywords, and descriptions for different pages using the universal TDK tag `tdk`?

In website operation, optimizing search engines (SEO) is a key link to obtaining natural traffic.And TDK (Title, Description, Keywords) as the first impression of the page presented in search engine results, its importance is self-evident.It not only affects the ranking of the website on the search results page, but also directly determines whether the user will click to enter your website.AnQiCMS knows the value of TDK for SEO and therefore provides a highly flexible and powerful universal TDK tag——`tdk`.

2025-11-07

How to manage and display static page content for single-page list tags `pageList` and single-page detail tags `pageDetail`?

In website operation, static pages play an indispensable role, they usually carry fixed and not frequently updated core content such as "About Us", "Contact Information", "Privacy Policy", and "Service Introduction".AnQi CMS provides two powerful tools for the management and display of these pages: the single-page list tag `pageList` and the single-page detail tag `pageDetail`.These two work together to allow you to easily handle the static content of the website, whether it's building navigation, displaying service lists, or presenting detailed corporate introductions, you can do it with ease.###

2025-11-07

How to filter and paginate articles or products by conditions in the document list label `archiveList`?

In Anqi CMS, when we want to display a series of articles, products, or other content on the website page, the `archiveList` tag is an indispensable powerful tool.It can not only help us flexibly extract and display various types of content, but also perform precise filtering according to multiple conditions, and elegantly implement the pagination display of content, thereby greatly enhancing the user's browsing experience and the information organization efficiency of the website.

2025-11-07

How to retrieve and display the full content of a single document using the `archiveDetail` detail tag?

In AnQi CMS, displaying the full content of a single document is the foundation of website operation.Whether you are publishing a news article, a product detail, or a service introduction, the core lies in how to present the data entered in the background efficiently and accurately to the user.This is where the `archiveDetail` tag and its related mechanism come into play.

2025-11-07

How to implement navigation display between content for previous/next document tags `prevArchive`/`nextArchive`?

In website operation, providing readers with a smooth reading experience is the key to enhancing user satisfaction and website value.After a user finishes reading an exciting article or product introduction, if they can conveniently see related content such as 'Previous' or 'Next', it will undoubtedly greatly increase their time spent on the website, forming a more natural browsing path, which is very beneficial for SEO optimization and content dissemination.AnQi CMS, as a powerful content management system, fully understands this need

2025-11-07