How to retrieve and display details of a specific category, including description, content, and Banner image?

Calendar 👁️ 62

When operating a website, we often need to display unique content for different category pages, such as a product category may have a detailed introduction and a prominent Banner image, while a news category focuses more on concise descriptions.AnQi CMS provides a flexible mechanism that allows us to easily obtain and display detailed information about specific categories, including descriptions, content, and Banner images.

Backend settings are fundamental: to enrich the content of categories

Before displaying the category details on the front-end, we need to fill in this information in the Anqi CMS backend. This is like preparing a "business card" for your category.

  1. Enter Category Management:Log in to the AnQi CMS backend, navigate to the 'Content Management' menu, and then click 'Document Category'. Here, you can see the list of all categories.
  2. Edit or add a category:Select a category that needs to display detailed information, click the 'Edit' button to enter its details page; or, you can also add a new category.
  3. Enter key information:
    • Category NameThis is the category title, which will be displayed on the front end.
    • Category introductionThis is usually used for search engine optimization (SEO) purposes.descriptionTag, which can also be used as a brief introduction on the page.
    • Category contentThis is a rich text editor, where you can add more detailed classification descriptions, pictures, and content.
    • Banner imageIn the 'Other Parameters' section, you will find the 'Banner Image' option.You can upload multiple images, which can be used as the carousel or main visual image on the category page.It is recommended to use images of the same size when uploading to maintain aesthetics.
    • Thumbnail: Similarly, in the "Other parameters", you can upload a category thumbnail, which is used in the list or other places where a small image needs to be displayed.

Ensure that this content has been filled in and saved properly, so that the front-end template can call and display it correctly.

Core tags:categoryDetailusefulness

Anqi CMS provides a namedcategoryDetailThe template tag, it is a powerful tool for us to get the details of the category. This tag can help us get the information of the current category page we are visiting, or the various information of the category specified by the ID.

Get the category details of the current page

When your visitor is browsing a category page, such as the "Product Display" category, we usually want to directly obtain the detailed information of this "Product Display" category. In this case,categoryDetailThe label intelligently identifies the category of the current page, we do not need to specify any ID, just throughnameparameters to obtain the corresponding field.

For example, to display the title of the current category:

{% categoryDetail with name="Title" %}

Get details of a specified category

Sometimes, you may need to specify a non-category page or want to display information about multiple categories on a single page, in which case you need to make it clear thatcategoryDetailThe tag to get data for which category. We can specify it throughidortokenthe (URL alias) parameter.

For example, if you know the ID of a category is10, and you want to get its title:

{% categoryDetail with name="Title" id="10" %}

Or if the category URL alias isabout-us:

{% categoryDetail with name="Title" token="about-us" %}

Display the category description and content

NowcategoryDetailTags, displaying the description and content becomes very direct.

Display the category description (Description)

Category descriptions are usually plain text and can be output directly:

<p>分类描述:{% categoryDetail with name="Description" %}</p>

If you want to assign the description content to a variable for subsequent processing, you can do it like this:

{% set categoryDescription = categoryDetail with name="Description" %}
<p>{{ categoryDescription }}</p>

Display category content (Content)

Categories typically contain HTML code generated by rich text editors. In order for the browser to correctly parse and render these HTML, we need to use|safeFilter. If the content is in Markdown format, we can also choose to userender=trueparameters to allow the system to convert it to HTML.

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

If the background content is in Markdown format and you want the system to automatically render it as HTML:

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

Display the category Banner image and thumbnail

Visual elements of categories are crucial for enhancing the aesthetic appeal and information conveyance of the page.

Display Category Banner Image (Images)

The Category Banner images usually support uploading multiple images in the background.categoryDetailtag to obtainImagesWhen the field is called, it will return an array of image URLs. We can iterate over this array to display all Banner images, or take only the first one as the main Banner.

Traverse all Banner images:

<div class="category-banners">
    {% categoryDetail categoryImages with name="Images" %}
    {% for imageUrl in categoryImages %}
        <img src="{{ imageUrl }}" alt="分类Banner图">
    {% endfor %}
</div>

Only display the first Banner image:If you only want to display the first Banner image and need to judge if it exists, you can do it like this:

{% categoryDetail categoryImages with name="Images" %}
{% if categoryImages %}
    <img src="{{ categoryImages[0] }}" alt="分类主Banner图">
    {# 也可以把它作为背景图 #}
    <div class="hero-banner" style="background-image: url('{{ categoryImages[0] }}');">
        <!-- 页面其他内容 -->
    </div>
{% endif %}

Display category thumbnails (LogoorThumb)

Category thumbnails are usually used in lists or other small display scenarios.LogoIt usually refers to large thumbnails, whileThumbIt refers to a smaller thumbnail that has been processed by the system.

<div class="category-thumbnail">
    <img src="{% categoryDetail with name="Thumb" %}" alt="分类缩略图">
</div>
<div class="category-logo">
    <img src="{% categoryDetail with name="Logo" %}" alt="分类大图">
</div>

Practice: Build a category detail page

Now, let's combine these tags to create a typical category detail page layout:

`twig {# Assume this is a page template for some category, such as products/list.html #} <!DOCTYPE html>

<meta charset="UTF-8">
{# 获取分类标题,并附加网站名称 #}
<title>{% tdk with name="Title" siteName=true %}</title>
{# 获取分类描述作为页面Meta Description #}
<meta name="description" content="{% categoryDetail with name="Description" %}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/style.css">

<header>
    {# 头部导航等通用元素 #}
</header>

<main class="container">
    <nav class="breadcrumb">
        {% breadcrumb crumbs with index="首页" %}
        <ul>
            {% for item in crumbs %}
                <li><a href="{{item.Link}}">{{item.Name}}</a></li>
            {% endfor %}
        </ul>
        {% endbreadcrumb %}
    </nav>

    <section class="category-header">
        {# 显示分类标题 #}
        <h1>{% categoryDetail with name="Title" %}</h1>

        {# 显示分类Banner图(取第一张作为主图) #}
        {% categoryDetail categoryBanners with name="Images" %}
        {% if categoryBanners %}
        <div class="main-banner">
            <img src="{{ categoryBanners[0] }}" alt="{% categoryDetail with name="Title" %} Banner">
        </div>
        {% endif %}

        {# 显示分类描述 #}
        {% set categoryDescription = categoryDetail with name="Description" %}
        {% if categoryDescription %}
        <p class="category-intro">{{ categoryDescription }}</p>
        {% endif %}
    </section>

    <section class="category-full-content">
        {# 显示分类详细内容 #}
        {% set categoryFullContent = categoryDetail with name="Content" render=true %} {# 假设后台内容可能是Markdown #}
        {% if categoryFullContent %}
        <div class="rich-text-content">
            {{ categoryFullContent|safe }}
        </div>
        {% endif %}
    </section>

    <section class="category-products-list">
        <h2>{% categoryDetail with name="Title" %} 下的文章/产品</h2>
        {# 在这里可以调用 archiveList

Related articles

How to add and display a captcha in the comment or message form to prevent spam?

When operating a website, spam comments and malicious messages are always a headache, as they not only affect user experience but may also damage the professional image of the website.Fortunately, AnQi CMS provides a simple and effective way to solve this problem - that is to add a captcha to the comment or message form.This can greatly enhance the security of the website, filtering out most automated spam information.Below, let's take a detailed look at how to add a captcha to your comment and message form in Anqi CMS.This process can be divided into two steps, which is very intuitive and easy to operate.### Step 1

2025-11-08

How to retrieve and display the list of friend links of a website?

In website operation, friendship links play an important role in connecting each other, promoting traffic, and improving search engine rankings.A well-maintained, clear display of the friendship link area, which not only reflects the openness of the website, but also provides users with more valuable jump paths.AnQiCMS provides users with a convenient friend link management feature, allowing you to easily obtain and display these links on your website. ### Manage your friend links: Backend settings Before starting the front-end display, we need to make sure that the friend links have already been configured in the Anqi CMS backend. Usually

2025-11-08

How to get and display the list of all documents associated with a specified Tag?

Manage content in AnQi CMS, besides organizing through categories, flexibly using the "Tag" feature is also the key to improving the aggregation ability of website content and user experience.Tags can connect documents of different categories, different models, but with the same theme, providing visitors with more ways to discover content.How can we specifically retrieve and display the list of all documents associated with the specified tags?Next, we will delve deeper into this practical skill. ### Understanding the Tag System of AnQi CMS The tag design of AnQi CMS is very flexible, it does not depend on any specific category or model

2025-11-08

How to get and display the custom parameters of a specified document (such as author, source)?

When using AnQi CMS to manage your website content, you may find that relying solely on default fields such as title, content, and summary is not enough to fully meet the needs of personalized display.For example, you may wish to display 'author' and 'source' information on the article detail page, or show 'material' and 'size' and other specific parameters on the product page.The AnQi CMS provides powerful custom parameter features, allowing you to easily add, manage, and display these personalized information for different types of documents (such as articles, products).This article will provide a detailed introduction on how to obtain and display custom parameters of specified documents in AnQi CMS

2025-11-08

How to implement nested category display with multiple levels and how to judge if there is a subcategory in the template?

When building a website, a clear and organized content structure is crucial for enhancing user experience and SEO performance.AnQiCMS (AnQiCMS) relies on its flexible content model and powerful template engine, allowing us to easily implement complex multi-level nested display and subcategory judgment, thus creating highly customized navigation and content layouts. ### Backend Settings: Build Category Hierarchy In the Anqi CMS backend, the category management feature (usually located under the "Content Management" menu, below "Document Category") is the foundation for implementing multi-level categorization. First

2025-11-08

How to integrate a category list in the navigation menu and display product documents under each category?

In AnQi CMS, integrating product categories into the navigation menu and displaying the product documents below is a crucial step to enhance website user experience and content organization efficiency.This can help visitors quickly find the information they need, and it also helps search engines better understand the structure of the website. To achieve this goal, we need to make some basic settings in the Anqi CMS backend and integrate the corresponding code in the template files according to these settings.

2025-11-08

How to obtain and display the links and titles of the previous and next articles?

When we manage and publish content in Anqi CMS, in order to enhance the user experience and content discoverability of the website, it is usually necessary to provide the function of navigating to the 'previous article' and 'next article' on the article detail page.This not only encourages readers to continue browsing the content within the site, but also provides a good internal link structure for search engine optimization (SEO).The Anqi CMS provides a very concise and intuitive template tag, allowing us to easily meet this requirement.### Core Functionality: `prevArchive` and `nextArchive`

2025-11-08

How to retrieve and display the Logo, thumbnail, and slideshow group on a single page?

In Anqi CMS, single pages (such as "About Us", "Contact Us", etc.) can not only carry rich text information but also greatly enhance the attractiveness and professionalism of the page through visual elements.Retrieve and display the Logo, thumbnail, and slideshow group on a single page, which is a key step to optimize the page display effect.AnQi CMS provides flexible template tags, allowing you to easily achieve these functions.### Understand the composition of visual elements on a single page In Anqi CMS, each single page can have exclusive visual elements to meet different display needs

2025-11-08