How to retrieve and display detailed information of a specified category, including its description, Banner image, and Logo?

Calendar 👁️ 71

In a content management system, categories are not only the form of content organization, but also the core of website structure and user navigation.Flexibly obtain and display detailed information of specific categories, such as their descriptions, unique banner images and logos, which is crucial for creating attractive and informative pages.AnQiCMS provides an intuitive and powerful template tag for this, allowing you to easily meet this requirement.

Core feature tags:categoryDetail

Aq CMS provides powerful template tags for this-categoryDetail. This tag's core function is to accurately retrieve all detailed data of the category specified by the classification ID or URL alias (token).Whether you want to display a selected category on the homepage or reference the detailed information of a specific content category on other pages,categoryDetailThey can all provide the data support needed.

To use it, you usually start with this format:{% categoryDetail myCategory with id="分类ID" %}. Here,myCategoryIs a custom variable name, you can name it according to your own preference, it will carry the detailed classification information obtained.idThe parameter is used to specify the category ID you want to retrieve. If you are not convenient to obtain the ID, you can also usetokenparameter, which corresponds to the URL alias of the category, for example:{% categoryDetail myCategory with token="company-news" %}.

Retrieve category description

The detailed description is an important part of introducing the category content to visitors, it helps users quickly understand the theme and scope of the category. ThroughcategoryDetailAfter obtaining the category data with the label, we can easily access itDescriptionfield.

In the template, you can display the category description in this way:

{% categoryDetail myCategory with id="123" %} {# 假设要获取ID为123的分类信息 #}
{% if myCategory %}
    <div class="category-description">
        <h3>{{ myCategory.Title }} 的详细描述</h3>
        <p>{{ myCategory.Description | safe }}</p>
    </div>
{% endif %}

Please note,DescriptionField content may contain HTML tags. To ensure that these HTML codes are rendered correctly by the browser rather than displayed as plain text, we need to use|safeFilter. This ensures that formats such as paragraphs, links, or bold text are displayed correctly.

Display category Banner image and Logo

Visual elements play a crucial role in attracting user attention, as they can convey brand image and content themes intuitively.The AnQi CMS allows you to configure exclusive Banner images and Logos for each category, making your website more visually appealing.

The category logo is usually a small identifying image of the category, which can be obtained directly throughLogothe field. While the banner image is more flexible, it is stored in the form of a group of images.ImagesIn the field. This means you can upload multiple Banner images for the same category and display them in a template in a loop, or just take the first one as the main Banner.

How to display the category Logo and Banner image in the template example:

{% categoryDetail myCategory with id="123" %} {# 假设要获取ID为123的分类信息 #}
{% if myCategory %}
    <div class="category-visuals">
        <h2>{{ myCategory.Title }}</h2>

        {# 显示分类Logo #}
        {% if myCategory.Logo %}
            <div class="category-logo">
                <img src="{{ myCategory.Logo }}" alt="{{ myCategory.Title }} Logo" style="max-width: 150px; height: auto;" />
            </div>
        {% endif %}

        {# 显示分类Banner图(图片组) #}
        {% if myCategory.Images %}
            <div class="category-banners">
                {% for banner in myCategory.Images %}
                    <img src="{{ banner }}" alt="{{ myCategory.Title }} Banner {{ forloop.Counter }}" style="max-width: 100%; height: auto; margin-bottom: 10px;" />
                {% endfor %}
            </div>
        {% elif myCategory.Logo %} {# 如果没有Banner组图,可以考虑将Logo作为备用Banner展示 #}
            <div class="category-main-banner">
                <img src="{{ myCategory.Logo }}" alt="{{ myCategory.Title }} 主Banner" style="max-width: 100%; height: auto;" />
            </div>
        {% endif %}
    </div>
{% endif %}

In this example, we first checkmyCategory.LogoDoes it exist, if it exists then display the Logo image. Next, we checkmyCategory.Images(Banner group), if present, then loop to display all Banner images.We have also added a backup logic, that is, if the category is not configured with a Banner group, but there is a Logo, then the Logo can be displayed as the main Banner, which increases the robustness and flexibility of the template.

Integrated application: Retrieve and display all information

Integrate the above elements, you can display a complete information block for a specified category at any position on the page:

{% categoryDetail featuredCategory with id="456" %} {# 获取ID为456的特色分类信息 #}
{% if featuredCategory %}
    <section class="featured-category-block">
        <h2 class="category-title">{{ featuredCategory.Title }}</h2>

        {% if featuredCategory.Logo %}
            <div class="category-header-logo">
                <img src="{{ featuredCategory.Logo }}" alt="{{ featuredCategory.Title }} Logo" style="height: 60px; width: auto; float: left; margin-right: 15px;" />
            </div>
        {% endif %}

        <div class="category-description-text">
            <p>{{ featuredCategory.Description | safe }}</p>
        </div>
        <div style="clear: both;"></div> {# 清除浮动 #}

        {% if featuredCategory.Images %}
            <div class="category-hero-banners" style="margin-top: 20px;">
                {% for banner in featuredCategory.Images %}
                    <img src="{{ banner }}" alt="{{ featuredCategory.Title }} 精选图 {{ forloop.Counter }}" style="width: 100%; height: auto; margin-bottom: 15px; border-radius: 5px;" />
                {% endfor %}
            </div>
        {% endif %}

        <a href="{{ featuredCategory.Link }}" class="view-all-button" style="display: block; text-align: center; padding: 10px 20px; background-color: #007bff; color: white; text-decoration: none; border-radius: 5px;">
            查看所有 {{ featuredCategory.Title }} 内容
        </a>
    </section>
{% else %}
    <p>抱歉,未能加载特色分类信息。</p>
{% endif %}

In practice, you would want tostyleReplace properties with external CSS styles to keep the code clean and maintainable.Through such a layout, visitors can clearly see the category logo, attractive banner images, and detailed descriptions, and can further explore related content through category links.

Frequently Asked Questions (FAQ)

Related articles

How to retrieve and loop through all document lists under a specific Tag (label) in the template?

In AnQi CMS, content organization can not only be achieved through traditional classification methods, but also flexible "Tag" mechanisms provide a wide space for content association and user search.When you want to display all documents under a specific tag in a certain area of the website, such as the sidebar, related recommendation modules, or even a dedicated Tag aggregation page, AnQi CMS provides a powerful and intuitive template tag that makes this process easy.This article will delve into how to use the Anqi CMS template

2025-11-08

How does AnQiCMS define and display related articles? Is it based on keywords or manual association?

In website operation, recommending relevant articles is an important strategy to enhance user experience, extend user stay time, and optimize on-site SEO.AnQiCMS provides a flexible and efficient mechanism to define and display related articles, allowing operators to choose between intelligent recommendations or manual association according to their actual needs. ### Smart Recommendation: Dynamic Association Based on Keywords and Tags The smart recommendation mechanism of AnQiCMS mainly relies on the keywords and tags set in the article content. When you edit articles in the background, you can set: * **Document keywords

2025-11-08

How to dynamically fetch and display the previous and next articles of the current article on the article detail page?

In website operation, how to allow users to smoothly jump to related or the next article after reading an article is the key to improving user experience and website stickiness.Especially for sites with a large amount of content, such as blogs, information stations, or product display websites, a intuitive 'Previous/Next' navigation function is particularly important.It can not only guide users to deeply browse and reduce the bounce rate, but also provide more internal links for search engines to optimize the SEO performance of the website.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers this need

2025-11-08

How to retrieve the custom fields (such as author, source, additional parameters) of the current article and display them?

In Anqi CMS, managing and displaying custom fields for articles such as authors, sources, or additional parameters is a common and practical need in content operation.The Anqi CMS, with its flexible content model design, provides multiple ways to achieve this goal, helping you easily enrich article information and present it to readers in a personalized manner. ### Understanding AnQi CMS Custom Fields Firstly, we need to understand how article custom fields work in AnQi CMS.

2025-11-08

How to implement a multi-level nested tree structure display in the category list?

When building website categories, we often need to display a clear, hierarchical structure so that users can intuitively understand the ownership of the website content.AnQiCMS provides powerful template tag features, fully supporting the display of multi-level nested tree structures in category lists, helping you easily create a user-friendly navigation system.The core of achieving this effect lies in the clever use of the `categoryList` template tag of Anqi CMS and its built-in hierarchical judgment function.By looping in the template, you can use the parent-child relationship of the category

2025-11-08

How to display the main category in the navigation bar and show the latest products under this category in the dropdown menu?

In website operation, a clear and effective navigation system is the key to improving user experience and website professionalism.AnQiCMS (AnQiCMS) with its flexible content management and powerful template engine, can help us easily achieve complex navigation requirements.Today, let's discuss how to display the main categories in the website's navigation bar and also show the latest products under the category in a dropdown menu when the mouse hovers over it.### One, Understand the navigation and content management basics of AnQiCMS One of the core advantages of AnQiCMS lies in its modular content management system

2025-11-08

How to get and loop through all independent pages in AnQiCMS template (such as About Us)?

In AnQi CMS, sometimes we need to list some independent pages in the website's navigation bar, footer, or other specific areas, such as "About Us", "Contact Us", "Privacy Policy", and so on.These pages usually contain fixed content and do not belong to a specific category or article model. AnQiCMS refers to them as 'single pages'.Fortunately, AnQiCMS provides a very intuitive and powerful template tag that can easily retrieve and loop through information for these single pages.### Core Tag

2025-11-08

How to get the complete content, SEO information, and associated images of a single page?

In daily website operations, independent pages such as "About Us", "Contact Information", etc., play an important role in conveying core information and shaping the brand image.As content operators, we often need to gain a deep understanding of the structure of these pages, including their main content, SEO information, and all associated image resources, in order to carry out fine management, optimization iteration, or flexible page layout.AnQiCMS provides an intuitive and powerful template tag system, making it easy to obtain these page data.

2025-11-08