How to retrieve and display detailed information of a specific category (such as description, Banner image)?

Calendar 👁️ 57

In AnQi CMS, it is crucial to flexibly obtain and display detailed information about categories, such as descriptions, banners, or thumbnails, which is essential for building a rich and visually appealing website.Whether it is necessary to display a brief introduction on the category list page or to quote the promotional picture of a specific category on a particular page, Anqi CMS provides intuitive and powerful template tags to help you meet these needs.

To retrieve detailed information about a category, we mainly rely oncategoryDetailThis template tag. This tag is specifically designed to extract various data items of a single category, allowing you to precisely control how this content is presented on the front-end page.

Core tags:categoryDetailUsage of

categoryDetailthe basic usage of tags is{% categoryDetail 变量名称 with name="字段名称" %}where,“variable name”is optional,if you specify a variable name,you can later refer to the data obtained through this variable;If not specified, the tag will directly output the value of the field.

This label's most commonly used parameter isnameIt is used to specify the specific fields of the category information you want to obtain. For example, to get the description of the category, you would usename="Description"; To retrieve the banner image, it will usename="Images".

In addition, you can also useidortokenparameters to specify which category of information to retrieve:

  • idParameters: Specify the unique numeric ID of the category. For example,id="10"It will fetch the category information with ID 10.
  • tokenParameter: Specify through the category URL alias (custom URL). For example,token="news-center"Will get the category information with the URL alias "news-center".

If notcategoryDetailthe tagidortokenIt will intelligently try to obtain the category information associated with the current page.This is very convenient on the category list page or category detail page, as you do not need to manually specify the ID, the system will automatically identify the current category.

Get and display category description

Category descriptions are usually used to briefly introduce the content of the category and are also very helpful for SEO.In the Anqi CMS backend, you can fill in the "Category Introduction" field on the "Document Category" editing page.

In the template, you can retrieve and display it in the following way:

{# 假设这是在某个分类页面,自动获取当前分类的描述 #}
<div>分类简介:{% categoryDetail with name="Description" %}</div>

{# 如果您想获取指定ID(例如ID为5)的分类描述 #}
<div>关于我们分类简介:{% categoryDetail with name="Description" id="5" %}</div>

{# 将描述内容赋值给一个变量,再进行处理或显示 #}
{% categoryDetail categoryDesc with name="Description" %}
<p>{{ categoryDesc|safe }}</p>

Please note that if the category description may contain HTML tags (such as formatted content entered in the background rich text editor), it is recommended to use|safeA filter to ensure that HTML content is parsed and displayed correctly, rather than being escaped as plain text.

Display the category Banner image and thumbnail

The banner image and thumbnail are an important part of the website's visual presentation.On the Anqi CMS backend's 'Document Category' editing page, you can upload 'Banner images' (supporting multiple) and thumbnails.

Get the category thumbnail (Logo/Thumb)

A category thumbnail usually refers to a representative image. In Anqi CMS, you can usename="Logo"orname="Thumb"to get:

{# 获取当前分类的缩略图大图 #}
<img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}" />

{# 获取当前分类的缩略图 #}
<img src="{% categoryDetail with name="Thumb" %}" alt="{% categoryDetail with name="Title" %}" />

{# 获取指定ID(例如ID为5)分类的缩略图 #}
<img src="{% categoryDetail with name="Logo" id="5" %}" alt="{% categoryDetail with name="Title" id="5" %}" />

Herealtthe title of the category is usually used as an attributename="Title"to fill in order to facilitate SEO and accessibility.

Display category banner image (Images)

Category banners are usually a set of images that can be used for slideshows or multi-image displays.name="Images"It will return an array of image URLs. Since it is an array, you need to useforloop to traverse and display them.

{# 假设您正在一个分类页面,要显示该分类的所有Banner图 #}
<div class="category-banner-slider">
    {% categoryDetail bannerImages with name="Images" %}
    {% for image_url in bannerImages %}
        <img src="{{ image_url }}" alt="{% categoryDetail with name="Title" %}" />
    {% endfor %}
</div>

{# 如果您只需要显示第一张Banner图 #}
{% categoryDetail bannerImages with name="Images" %}
{% if bannerImages %} {# 确保图片数组不为空 #}
    <div class="main-banner" style="background-image: url('{{ bannerImages[0] }}');">
        {# 这里可以放一些叠加的文字或按钮 #}
    </div>
{% endif %}

By{% if bannerImages %}such a judgment to avoid template errors when no image is uploaded.bannerImages[0]You can directly get the first picture in the array.

Get the content of the category and custom fields.

In addition to the description and images, the category may also have a longer "category content" or fields that you customize for the model in the backend.

Get category content (Content)

If the category content is rich, you can fill in the "category content" field on the backend. The way to obtain it in the template is similar to the description:

{% categoryDetail categoryContent with name="Content" %}
<div class="category-full-content">
    {{ categoryContent|safe }} {# 同样,如果包含HTML,使用|safe #}
</div>

Get Custom Field

The Anqi CMS allows you to add custom fields to content models (which can affect categories). If you create a category model namedcustom_field_nameThe field, you can directly access by its name:

{# 获取名为 custom_field_name 的自定义字段的值 #}
<div>自定义信息:{% categoryDetail with name="custom_field_name" %}</div>

{# 如果您想遍历所有自定义字段,可以使用 name="Extra" #}
{% categoryDetail categoryExtraFields with name="Extra" %}
<div class="custom-fields">
    {% for field in categoryExtraFields %}
        <div>
            <span>{{ field.Name }}:</span>
            <span>{{ field.Value }}</span>
        </div>
    {% endfor %}
</div>

name="Extra"Will return an array containing all custom fields, each field includesName(field display name) andValue(Value) attribute, you can traverse and display it as needed.

CombinecategoryListTag

In some cases, you may first need to traverse the category list, and then display the details of each category. At this point, you can integratecategoryDetailthe logic intocategoryListin the loop. For example, when outputting the first-level categories in the loop, display the thumbnail and description of each category:

{% categoryList categories with moduleId="1" parentId="0" %} {# 获取文章模型下所有顶级分类 #}
    {% for category in categories %}
    <div class="category-item">
        <h3><a href="{{ category.Link }}">{{ category.Title }}</a></h3>
        {# 直接使用 category 变量中包含的 Logo 和 Description 字段 #}
        {% if category.Thumb %}<img src="{{ category.Thumb }}" alt="{{ category.Title }}" />{% endif %}
        <p>{{ category.Description }}</p>
    </div>
    {% endfor %}
{% endcategoryList %}

Please note,categoryListThe tag is in the loop,itemvariable (here iscategory) already includes the categories'Title/Link/Description/Logo/Thumbetc. common fields, no need to use them againcategoryDetailTo obtain this basic information, simply go through{{ category.字段名 }}You can call it. Only when you need to obtain other deeper or less commonly used information of the current loop category (such asImagesWhen using array or some specific custom fieldcategoryListin the loop againcategoryDetailLabel and pass inid=category.Id.

By using the above method, you can flexibly display any detailed category information you want on the front page of the Anqi CMS website, whether it is text description, a single image, or a multi-image banner.


Frequently Asked Questions (FAQ)

Q1: If my category description (Description) or content (Content) contains HTML code, why is the original code displayed on the page instead of the rendered effect?

A1: This is because the Anqi CMS template engine, for security reasons, defaults to escaping all output HTML content, which<to&lt;to prevent potential XSS attacks. If you are sure that this content is safe and need to render HTML effects, you can use it in the output.|safea filter. For example:{{ categoryDesc|safe }}.

**Q

Related articles

How to display a category list based on content model or parent-child relationship?

AnQi CMS is an efficient enterprise-level content management system that provides great flexibility in content organization and display.For many websites, how to display a category list based on different content models or the hierarchical relationship of categories is a very common and important need.This concerns not only the organization structure of the website content, but also directly affects the user experience and SEO effect.In Anqi CMS, implementing such a display is not complicated.The built-in template tags provide us with powerful functions, allowing us to easily control the output of the classification list

2025-11-08

How to correctly display the breadcrumb navigation path on the content page?

Breadcrumb Navigation is a very common and practical navigation method on websites, which can clearly display the current position of the user in the website hierarchy, just like breadcrumbs scattered in the forest guiding the way home.For users, breadcrumb navigation not only helps them quickly understand the hierarchical relationship of the current page in the entire website, but also facilitates their return to the previous level or higher-level pages, greatly enhancing the user experience of the website.At the same time, for search engine optimization (SEO)

2025-11-08

How to build and display multi-level navigation menus on a website?

The website navigation menu is a guidepost for users to browse the website content, a well-designed multi-level navigation system can significantly improve user experience, and help visitors quickly locate the required information.A clear, intuitive, and easy-to-use navigation is a key element for the success of a corporate website, product showcase page, or content portal.AnQi CMS is a comprehensive and flexible content management system that provides intuitive backend settings and powerful template tags, allowing you to easily build and manage multi-level navigation menus that meet various needs.

2025-11-08

How to dynamically set the page TDK information to optimize SEO display?

In today's digital age, Search Engine Optimization (SEO) is crucial for the success of any website, and the TDK information - that is, the page's Title (title), Description (description), and Keywords (keywords) - is a key factor for search engines to understand the content of the page and determine its ranking.If this information is set properly, it can not only improve the visibility of the website in search results, but also attract users to click and bring high-quality traffic. Manually setting TDK for each page is not only time-consuming and labor-intensive, but also prone to omission.Fortunately

2025-11-08

How to display all or part of a single-page list on a website?

In website operations, we often need to display some independent, fixed-content pages, such as 'About Us', 'Contact Information', or some policy descriptions, etc.In Anqi CMS, these are called "single pages". Effective management and presentation of these single pages not only makes the website structure clearer but also enhances the user experience.Next, we will discuss how to flexibly display all or part of a single-page list on a website.### **Understanding the Creation and Management of Single Pages (Backend Operations)** Before Starting the Frontend Display

2025-11-08

How to get and display all the content and associated images of a specific single page?

In Anqi CMS, a single page is an important part of the website content structure, such as "About Us", "Contact Information", and so on.Effectively acquire and display all the content of these single pages and associated images, which is crucial for the communication and visual expression of the website.Aanqi CMS provides an intuitive backend management and flexible template tags, making this process very convenient. ### Easily set up single page content and images in the background First, we need to create and edit single page content in the Anqi CMS backend management system. This is usually performed under the 'Page Resources' section in the 'Page Management' module

2025-11-08

How to display a document list based on different conditions (such as categories, recommended properties)?

In Anqi CMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether based on the category of the article or the recommended attributes of the content, the system provides powerful and easy-to-use template tags that allow you to easily customize the display of the document list. ### Core Tool: `archiveList` Document List Tag The core tool used in AnQi CMS to control the display of document lists is the `archiveList` tag.It allows you to filter, sort, and limit the number of displayed documents based on multiple conditions

2025-11-08

How to display the complete article content on the article detail page, including lazy-loaded images?

How to elegantly display full content and lazy loading images on article detail pages in AnQi CMS In website content operations, the article detail page is an important touchpoint for users to obtain information and gain a deeper understanding of brands and products.A well-designed, fast-loading, and comprehensive article detail page that can greatly enhance user experience and effectively assist in SEO optimization.For users who use Anqi CMS, taking full advantage of its powerful template tag system can easily realize the complete presentation of article content, and combine modern web technologies to implement lazy loading of images, making your website both beautiful and efficient.###

2025-11-08