How to get the thumbnail and background Banner image of the `categoryDetail` tag?

Calendar 👁️ 64

In AnQi CMS, the visual presentation of a website is crucial for attracting visitors and conveying the brand image.The thumbnail and background Banner image play an important role in web page design, as they can intuitively display the category content and enhance the aesthetics and user experience of the page.AnQi CMS provides flexible and easy-to-use template tagscategoryDetailHelp us easily obtain and display these visual elements.

UnderstandingcategoryDetailTag

categoryDetailThe tag is a powerful tool in the Anqi CMS template system for obtaining detailed information of specific categories.Whether it is the category the current page is in, or any category specified by ID or alias, you can obtain its title, description, link, as well as the thumbnail and background Banner image we focus on today through this tag.

Its basic usage form is usually like this:{% categoryDetail 变量名称 with name="字段名称" id="分类ID" %}

Among them,变量名称Can be any variable name you customize to store the data obtained.name="字段名称"Then it specifies the specific information you want to obtain, such as category titles, category links, etc.;id="分类ID"ortoken="分类别名"It is used to precisely specify which category of information you want to obtain. If omittedidortokenparameter,categoryDetailThe label automatically retrieves the detailed information of the category to which the current page belongs, which is very convenient on the category list page or category detail page.

Get the category thumbnail

In the AnQi CMS category settings, you can upload a thumbnail for each category, which is usually used for an overview display in the category list.categoryDetailTags providedThumbandLogoTwo fields to get these images.

  • Thumbfield: Typically used to obtain the category's thumbnail, suitable for small-sized icons or list images.
  • LogofieldUsed to obtain the larger thumbnail size of a category, which may be used as the category header image in some designs.

To get and display the category thumbnail in a template, you can use the following method.categoryDetailTags:

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

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

{# 如果需要获取指定ID分类的缩略图,例如分类ID为5的缩略图 #}
<img src="{% categoryDetail with name='Thumb' id='5' %}" alt="{% categoryDetail with name='Title' id='5' %}" />

Please note,altThe attribute is very important for images, as it not only improves SEO friendliness but also provides text descriptions when the image cannot be loaded. We usually combinecategoryDetail with name='Title'to dynamically fill in.altProperty.

These thumbnails are usually uploaded and set in the 'Content Management' -> 'Document Category' section when editing categories in the 'Thumbnail' field in the background.

Get the background Banner image of the category

In addition to thumbnails, the category page sometimes needs a background Banner image with stronger visual impact, especially at the top of the category or for carousel display.The Anqi CMS category management supports uploading multiple images as the Banner group image for the category.categoryDetailTag throughImagesfield to get these Banner images.

ImagesThe field returns an array of image URLs, therefore, if you need to display all Banner images (such as for a carousel), you can usefora loop to iterate over these images:

<div class="category-banner-carousel">
    {% categoryDetail categoryBanners with name="Images" %}
    {% for imageUrl in categoryBanners %}
        <img src="{{ imageUrl }}" alt="{% categoryDetail with name='Title' %}" />
    {% endfor %}
</div>

However, in many cases, we may only want to select one image (such as the first one) as the background Banner for the category page. At this time, you can getImagesThe first element in the array is applied to the HTML element.background-imageStyle:

{# 获取当前分类的Banner组图,并取出第一张作为背景图 #}
{% categoryDetail bannerImages with name="Images" %}
{% if bannerImages %} {# 确保有图片上传,避免报错 #}
    {% set firstBanner = bannerImages[0] %}
    <div class="category-hero-banner" style="background-image: url('{{ firstBanner }}'); background-size: cover; background-position: center; height: 300px;">
        {# 这里可以放置Banner上的文字内容,如分类标题等 #}
        <h1>{% categoryDetail with name='Title' %}</h1>
        <p>{% categoryDetail with name='Description' %}</p>
    </div>
{% endif %}

In the above example, we first take theImagesfield to assign the image array tobannerImagesthe variable, then throughbannerImages[0]Access the first element of the array (i.e., the first uploaded Banner image). Then, we use adivelement, through inline stylesbackground-image: url('...')Set the background image. To make the background image better adapt, you may also need to addbackground-size: cover;andbackground-position: center;CSS properties.

These Banner images are also edited in the "Content Management" -> "Document Category" section when editing categories in the "Banner Image" field for uploading and setting multiple images.

By using the above method, you can flexibly obtain and display category thumbnails and background Banner images in the Anqi CMS template, bringing more possibilities to website design.


Frequently Asked Questions (FAQ)

  1. Ask: Where in the backend are the thumbnail and Banner image for the category set?Answer: You can select 'Document Category' under the 'Content Management' module in the Anqi CMS backend and then edit the specific category.In the category editing page, you will see the fields "Thumbnail" and "Banner image", which are used to upload a single thumbnail and multiple Banner images.

  2. Why did I follow the example code, but the thumbnail or Banner image did not display on the page?There may be several reasons:

    • Image not uploaded:Please check if the thumbnail or Banner image has been uploaded for the corresponding category in the background.
    • The template file location is incorrect:Make sure your template file is correctly placed in/templatethe current theme folder under the directory.
    • Cache problem:If you change the template or background settings without refreshing the page in time, old content may be displayed.Please try clearing your browser cache or click the 'Update Cache' button in the Anqi CMS backend.
    • CSS style occlusion or impact:Check if there are unexpected occlusion or size issues with the CSS style of the page, which may cause the image to display incorrectly.
  3. Ask: If my category has uploaded multiple Banner images, but I want to display different Banner images in different positions, such as one for the background and one for the list cover, can it be done?Yes, it can be. BecauseImagesThe field returns an array of image URLs. You can access different images according to your needs. For example,{{ bannerImages[0] }}You can get the first image,{{ bannerImages[1] }}Get the second image, and so on. You can also combine it with the template.forLoop, displaying images selectively according to their order in the array or by other logical judgments.

Related articles

How to use the `archiveList` tag to display the thumbnail of each article on the list page?

In Anqi CMS, to make your website's content list page more attractive, displaying an eye-catching thumbnail for each article or product is the key to improving user experience and the beauty of the page.This not only helps visitors quickly understand the content topic, but also effectively improves the click-through rate.AnQiCMS provides an intuitive and powerful template tag feature, allowing you to easily achieve this goal on the list page.### Core Feature Revelation: `archiveList` Tag and Thumbnail The goal to be achieved in AnQiCMS

2025-11-08

What is the difference in fetching images between the `Logo` and `Thumb` fields in the `archiveDetail` tag?

When managing content in Anqi CMS, we often encounter various fields related to images, among which the `Logo` and `Thumb` fields under the `archiveDetail` tag often confuse new users.They all represent images, but there are very clear and practical differences in terms of usage and system processing.Understanding these differences can help us better plan the content of images, improve the loading speed of the website, and enhance the user experience.### `Logo` field

2025-11-08

How to enable the automatic compression of large images in AnQiCMS and specify the compression width?

In website operation, images are the key elements that attract users and enrich content.However, large-sized images, while bringing visual impact, may also become a bottleneck for website loading speed, affecting user experience and even search engine rankings.AnQi CMS knows this pain point, built-in efficient image processing features, including the highly praised "auto-compress large image".This feature is designed to help you significantly optimize website performance and storage space without sacrificing too much image quality. To enable and configure this utility feature, you just need to log in to the Anqi CMS backend management interface.Log in to the background after

2025-11-08

Does AnQiCMS support automatic conversion of images to WebP format to optimize thumbnail performance?

In website operation, image loading speed is one of the key factors affecting user experience and search engine ranking.The WebP format, as a modern image format, is gaining popularity among websites due to its excellent compression performance that significantly reduces file size while maintaining visual quality.So, does AnQiCMS support automatic conversion of images to WebP format to optimize thumbnail performance?The answer is affirmative. AnQiCMS fully considers the website's needs for image optimization and loading speed, and built-in WebP image format conversion function. When you are

2025-11-08

How to get the thumbnail or the first image of the slideshow group in the `pageDetail` tag?

In website operation, well-designed single-page (such as "About Us", "Service Introduction", etc.) is the key to showcasing brand image and conveying core information.These pages often need rich visual elements to attract visitors, and the effective use of images is an indispensable part of it.For users of AnQiCMS, the ability to flexibly obtain and display the first image from a thumbnail or slideshow is an important capability to achieve this goal.AnQi CMS provides a powerful template tag system

2025-11-08

The `thumb` filter can be used to process the image URL obtained from `categoryDetail` or `pageDetail`?

When using the AnQiCMS template, we often encounter the need to handle image links, especially for the display of thumbnails.The system provides multiple ways to obtain images, one common issue is about the combination of the `thumb` filter with the image fields in the `categoryDetail` or `pageDetail` tags.First, let's understand the basic logic of AnQiCMS in image processing.

2025-11-08

In AnQiCMS image resource management, how to replace an image while keeping the original URL unchanged?

In website content operation, images are indispensable visual elements that can effectively enhance the attractiveness and reading experience of the content.However, as the operation deepens, we often need to update the images to reflect the latest products, services, or design styles.

2025-11-08

How to prevent uploading large images from affecting the page loading speed in AnQiCMS?

## Using AnQiCMS, easily say goodbye to large image lag: full analysis of optimization strategies In today's digital age, website loading speed is a key factor in user experience and search engine rankings.Among them, images as an important part of content display are often also the main culprits that slow down the speed of the website.An unoptimized large image not only consumes a lot of bandwidth but also significantly prolongs the page loading time, leading to user loss.

2025-11-08