How to get and display the title, description, thumbnail, and associated content of the `categoryDetail` tag?

Calendar 👁️ 90

Manage and display website content in Anqi CMS,categoryDetailThe tag plays a crucial role.It is like the conductor of your website content display, able to accurately obtain and present all the detailed information of a specific category, whether it is the title, description, thumbnail, or deeper related content, it can help you a lot.

categoryDetailThe core role of tags

In simple terms,categoryDetailThe tag's mission is to retrieve detailed data for a single category.On the category page, it will automatically identify the category information of the current page and load it, but on other pages, you can also obtain data of any category by explicitly specifying the category ID or URL alias.This is particularly flexible when building navigation menus, related category recommendations, or multi-level content displays.

Use this tag, you will usually see it in this form:{% categoryDetail 变量名称 with name="字段名称" id="1" %}. Among them,变量名称It is optional, if you define it, you can later refer to the data obtained through this variable; if omitted, the label will output the result directly.idThe parameter is used to specify the numeric ID of the category, andtokenThe parameter allows you to locate the category using its URL alias. For users who have deployed multiple sites,siteIdParameters can help you call classification data across sites.

Get and display basic classification information.

category ofTitle(Title), anddescription(Description) is the most basic and commonly used information. They not only allow visitors to quickly understand the classification topics but are also key elements for Search Engine Optimization (SEO). For example, you can go through{% categoryDetail with name="Title" %}Display the category title directly on the page or assign it to a variable:{% categoryDetail categoryTitle with name="Title" %}{{categoryTitle}}. The way to obtain the category description is similar to the title, usually used to provide a brief overview on the category list page or fill the HTML page.<meta name="description">.

Sometimes, the category page itself may contain a paragraph.Detailed content(ContentThis is very common in some special topic categories or introductory categories.categoryDetailLabels can also retrieve this content. It is worth noting that if the category content is edited in the Markdown editor in the background, you may need to userender=trueParameters to ensure that Markdown syntax can be correctly parsed and rendered as HTML, while combining|safeFilters to prevent HTML code from being escaped:{{categoryContent|render|safe}}.

Flexibly display classification visual elements: thumbnails and banners

Visual content is crucial in attracting users,categoryDetailTags provide multiple ways to display classification image information.

Thumbnail: Categories usually have images for list display.LogoThe field usually represents the 'thumbnail full image' of the category, andThumbA field may represent a cropped or processed "thumbnail". Both directly return the image URL, and you can embed them.<img>label'ssrcthe attribute.

Banner group image: For some categories that require a carousel or multiple image display,Imagesfield comes into play. It returns an array of image URLs. This means you need to use aforLoop to iterate and display these images, for example:

{% categoryDetail categoryImages with name="Images" %}
<ul>
  {% for item in categoryImages %}
  <li>
    <img src="{{item}}" alt="{% categoryDetail with name="Title" %}" />
  </li>
  {% endfor %}
</ul>

If you only need to get the first image as the page background or cover, you can access it through the array index:{% set pageBanner = categoryImages[0] %}.

Custom field display

The flexible content model of AnQi CMS allows you to add various custom fields to categories. These fields may include contact information, specific attribute values, external links, and so on.categoryDetailTags can also access these custom fields.

If you want to iterate and display all custom fields, you can getExtrafields and then iterate over them inside:

{% categoryDetail extras with name="Extra" %}
{% for field in extras %}
  <div>{{field.Name}}:{{field.Value}}</div>
{% endfor %}

If you only want to retrieve a specific custom field, for example, if you have defined a field named in the backgroundcategorySloganyou can directly retrieve it by name:{% categoryDetail with name="categorySlogan" %}.

Retrieve associated content of categories

Category detail pages often show information about the category itself, but the most important is usually to display therelated content, such as article lists or product lists.categoryDetailThe tag does not directly return this content, but it provides the crucialId(Category ID), You can use this ID in conjunction witharchiveListtags to obtain.

archiveListThe tag is used to retrieve a list of documents (articles, products, etc.). On the category detail page, you can use it like this to retrieve all documents under the current category:

{% archiveList archives with categoryId=category.Id type="page" limit="10" %}
  {% for item in archives %}
  <li>
    <a href="{{item.Link}}">
      <h5>{{item.Title}}</h5>
      <p>{{item.Description}}</p>
      <img src="{{item.Thumb}}" alt="{{item.Title}}" />
    </a>
  </li>
  {% empty %}
  <li>此分类下暂无内容。</li>
  {% endfor %}
{% endarchiveList %}

here,categoryId=category.IdThat is the key point, it willcategoryDetailThe current category ID is passed toarchiveListto ensure that only documents under the category are displayed.type="page"means enabling pagination, whilelimit="10"controls the number of articles displayed per page.

Comprehensive example

Suppose you are building a category page for a blog website, you need to display the category name, description, a Banner image, and a list of the latest articles under the category. Your template code might look like this:

{% categoryDetail category %} {# 获取当前分类所有信息,并赋值给category变量 #}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>{{ category.Title }} - 我的博客</title>
    <meta name="description" content="{{ category.Description }}">
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <header>
        <h1>{{ category.Title }}</h1>
        <p>{{ category.Description }}</p>
    </header>

    <div class="category-banner">
        {% categoryDetail categoryBanner with name="Images" %}
        {% if categoryBanner %}
            <img src="{{ categoryBanner[0] }}" alt="{{ category.Title }}的封面图">
        {% endif %}
    </div>

    <main class="category-content">
        {% if category.Content %}
            <div class="intro-content">
                {{ category.Content|render|safe }}
            </div>
        {% endif %}

        <h2>{{ category.Title }}下的最新文章</h2>
        <ul class="article-list">
            {% archiveList articles with categoryId=category.Id type="page" limit="10" order="CreatedTime desc" %}
                {% for article in articles %}
                <li>
                    <a href="{{ article.Link }}">
                        <img src="{{ article.Thumb }}" alt="{{ article.Title }}">
                        <h3>{{ article.Title }}</h3>
                        <p>{{ article.Description }}</p>
                        <span>发布日期:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                    </a>
                </li>
                {% empty %}
                <li>此分类下暂无文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>

        <div class="pagination-area">
            {% pagination pages with show="5" %}
                {% for p in pages.Pages %}
                    <a href="{{ p.Link }}" class="{% if p.IsCurrent %}active{% endif %}">{{ p.Name }}</a>
                {% endfor %}
            {% endpagination %}
        </div>
    </main>

    <footer>
        <p>&copy; 2023 我的博客</p>
    </footer>
</body>
</html>

BycategoryDetailLabel, you can easily build a content-rich, well-structured category page, providing users with a better browsing experience, and also laying a solid foundation for search engine optimization.


Frequently Asked Questions (FAQ)

  1. categoryDetailandcategoryListWhat are the differences between tags? categoryDetailTags are used to retrieve and displaya singleAll the details of a category, such as the title, description, exclusive images, etc., of a specific category.categoryListTags are used to retrievemultipleA list composed of categories, commonly used to build navigation menus or sidebar category lists, it usually only returns brief information about categories (such as titles and links), and if detailed information about each list item is needed, it may be necessary tocategoryListnested inside a loopcategoryDetail.

  2. **I passedcategoryDetailgot the categorized content ("

Related articles

How to implement pagination for document list, related documents, and search results using the `archiveList` tag?

Manage website content in Anqi CMS, whether it is blog articles, product displays, or news information, efficient list display is indispensable.When the amount of content gradually increases, how to elegantly present a large number of documents and ensure that users can easily browse and search has become a key point that operators need to pay attention to.At this time, the `archiveList` tag and its accompanying pagination feature have become a powerful tool in our hands, it can not only implement pagination for conventional document lists, but also be flexibly applied to the display of related documents and search results.### Pagination display of document list Imagine

2025-11-07

How to retrieve and display specific fields (such as title, content, image) of the document detail page using the `archiveDetail` tag?

On Anqi CMS built websites, each document detail page is the key to displaying core content and attracting visitors to stay.To ensure that these pages can efficiently and flexibly present important information such as article titles, content, images, etc., it is particularly important to understand and make good use of the `archiveDetail` tag.It is the powerful tool that precisely locates and flexibly displays these core data.## Master the `archiveDetail` tag: Accurately locate and display document detail content When you create an article or product detail page in AnQiCMS

2025-11-07

How to create and display independent pages such as 'About Us' and 'Contact Us' in a single-page management?

In website operation, independent pages like "About Us" and "Contact Us" are essential basic content.They not only help visitors quickly understand the company and provide contact information, but are also a key window for building trust and showcasing the brand image.AnQiCMS (AnQiCMS) provides us with an intuitive and powerful single-page management function, making it easy and efficient to create and maintain these pages. Next, we will explore how to create, display these independent pages, and integrate them into the website navigation in Anqi CMS.### Step 1

2025-11-07

How to manage image resources and control their display in content (such as Webp, automatic compression, thumbnails)?

In website operation, images are indispensable elements that attract users and convey information.However, managing and optimizing these image resources is often a headache, as it directly affects the website's loading speed, user experience, and even the search engine optimization (SEO) effect.Fortunately, AnQiCMS provides a series of powerful and flexible features for image management, allowing you to easily cope with these challenges.Why is image management so important? Imagine a user opening your website and being unable to see the full content due to slow image loading

2025-11-07

How to get and display the title, content, and image of a single page using the `pageDetail` tag?

## AnQi CMS `pageDetail` tag: Easily obtain and display single page information Single pages (such as "About Us", "Contact Us", "Terms of Service", etc.) play an indispensable role in website content management.They usually carry stable, core information that does not need to be updated as frequently as articles or products.AnQi CMS provides an efficient and flexible tool for displaying this type of page - the `pageDetail` tag.Mastering the use of this tag will allow you to be proficient in template development, easily presenting beautifully designed single-page content

2025-11-07

How to dynamically generate the page Title, Keywords, and Description using the `tdk` tag to optimize SEO display?

In website operations, Search Engine Optimization (SEO) is a key link to improve website visibility and attract natural traffic.Among them, the page's `Title` (title), `Keywords` (keywords), and `Description` (description), abbreviated as TDK, are important signals for search engines to understand the content of the page and determine the ranking.An excellent TDK setting can make your website stand out in a sea of information.AnQiCMS (AnQiCMS) fully understands the importance of TDK and has integrated powerful TDK management functions into the system design from the very beginning

2025-11-07

How to build a multi-level navigation menu using the `navList` tag and display it on the front end?

AnqiCMS provides powerful and flexible configuration options for website navigation, allowing you to easily build multi-level navigation menus and customize the display on the front-end website according to business needs.Whether it is a simple single-layer menu or a complex multi-level navigation with dropdown content, the `navList` tag can help you a lot. To implement multi-level navigation, we first need to complete the configuration of the navigation structure in the background management system, which lays the foundation for the display on the front end.

2025-11-07

How does the `contact` tag dynamically display website contact information (phone, address, email, etc.)?

AnQiCMS (AnQiCMS) provides a flexible and efficient way to manage various types of information on a website, where the dynamic display of website contact information can be easily realized through its built-in `contact` tag.This means you do not need to manually modify the code, and can manage phone numbers, addresses, email information centrally in the background, and have them automatically updated to various pages of the website. ### One, set the website contact information centrally in the background To dynamically display contact information, you first need to enter this information into the Anqi CMS backend.The operation path is very intuitive: log in to the background after

2025-11-07