autocategoryDetailLabels play a very important role in building a website with rich content and clear structure.It can help us accurately obtain and display detailed information of specific categories, whether it is used for the header introduction on the category list page or to show more content of the category in the article detail page, it is very convenient.
categoryDetailauto
In simple terms,categoryDetailThe function of the label is to “get detailed information of a category”.This is similar to the logic of obtaining article details or single page details, which allows us to specify a category, then extract all related data such as the title, description, link, image, etc. of the category, and display them on the website front end.
auto
- Display the current category title, SEO description, and image at the top of the category list page.
- Display the name and link of the category to which the article or product belongs on the detail page, making it convenient for users to backtrack.
- On the website's sidebar or bottom navigation, dynamically display information for specific categories.
How to usecategoryDetailtags
categoryDetailThe basic syntax structure of tags 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, we can define a variable name.If you do not need to process it particularly, you can also omit the variable name by directly outputting the value of a certain field.name="字段名称"This is the most core parameter, it tells the tag which specific field of the category we need to retrieve. For example,name="Title"It will obtain the category title,name="Description"It will obtain the category description.
In addition to specifying the fields to be obtained, we can also use other parameters to specify which category:
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 label will try to get the information of the category to which the current page belongs by default.token="分类URL别名"If the category is set to a custom URL alias (usually in English or pinyin), it can also be specified by this alias.siteId="站点ID"In the multi-site management scenario of AnQiCMS, if you need to obtain the category information of other sites, you cansiteIdthe parameter to specify the target site.
Common fields and their application examples
categoryDetailLabels can obtain various information of categories, and below are some common fields and their applications in templates:
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>Category Link (
Link)Used to generate the jump link for the category page, ensuring that users can click to access the detailed content of the category.<!-- 创建一个指向当前分类的链接 --> <a href="{% categoryDetail with name="Link" %}"> {% categoryDetail with name="Title" %} </a>Category Description (
Description) and category content (Content)DescriptionUsed for SEO optimization or brief category introductions,Contentwhich is used to display the main content of the category page. IfContentThe field contains content formatted with Markdown, and the backend has enabled the Markdown editor, which will automatically render it into HTML; to manually control the rendering behavior, you can userenderparameters, such asname="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>Parent Category ID (
ParentId)When building multi-level category navigation or breadcrumb navigation, this field is very useful for determining the hierarchical relationship of the current category.<!-- 获取当前分类的上级分类ID --> {% categoryDetail currentCategoryParentId with name="ParentId" %} {% if currentCategoryParentId > 0 %} <div>上级分类ID:{{ currentCategoryParentId }}</div> {% endif %}Category thumbnail (
Thumb) And Category Large Image/Logo (Logo)Category images are usually used for displaying in category lists, or as the top Banner image on category pages.LogoUsually refers to the original or larger image,ThumbThis is a thumbnail that has been processed by the system.<!-- 在分类列表或详情页显示分类缩略图 --> <img src="{% categoryDetail with name="Thumb" %}" alt="{% categoryDetail with name="Title" %}">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,ImagesReturns an array of image URLs, therefore it needs to be paired withfora loop to iterate 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 %}分类的文档数量 (English)
ArchiveCount)The number of articles or products under the category can be displayed next to the category name, enhancing information volume and user experience.<h3> <a href="{% categoryDetail with name="Link" %}"> {% categoryDetail with name="Title" %} (共{% categoryDetail with name="ArchiveCount" %}篇文章) </a> </h3>Custom fieldsIf we set custom fields for categories in the content model of the background, these fields can also be accessed through
categoryDetailtags. Directly throughname="你的自定义字段名"the way.<!-- 如果有一个名为 "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
categoryDetailThe tag is an indispensable part of AnQiCMS template development, making the acquisition and display of classification information intuitive and efficient.By flexibly using the various parameters and fields it provides, we can easily build dynamic, user-friendly category pages, thereby effectively enhancing the organization of website content and SEO performance.categoryDetailAll of them can provide strong support.
Common Questions and Answers (FAQ)
Why is mycategoryDetailTag does not display any content?
The most common reason is that you have not specifiedidortoken, or the current page is not associated with any categories, causing the tags to be unable to automatically identify the categories to be retrieved.Make sure to explicitly specify the category ID or alias you want to retrieve when using it, or use it on the category page so that it can automatically retrieve the information of the current category.nameAre the parameters spelled correctly, and the category you are trying to retrieve the field data from actually exists?
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 name and value of each custom field. For example:{% categoryDetail extras with name="Extra" %}{% for field in extras %}
<div>{{ field.Name }}:{{ field.Value }}</div>{% endfor %}.
3.LogoandThumbWhat's the difference between the fields? Which one should I use?
Logo通常指的是分类的原始或较大尺寸的图片,可能用于分类页面的主视觉或大型Banner。而ThumbIt is usually a small thumbnail image automatically generated by the system according to preset rules, suitable for category lists, card displays, or places 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.