How to display detailed information and description of the current category in AnQiCMS?

Calendar 👁️ 60

When operating the AnQiCMS website, we often need to dynamically display detailed information and descriptions of the current category on the category page, such as the title, introduction, large picture, and even custom fields.This not only helps users better understand the theme of the current page, but also effectively improves the SEO performance of the page.Anqi CMS provides very flexible and intuitive template tags, making this task easy and simple.

Get to knowcategoryDetailTags: Your category information 'Smart Assistant'

The AnQi CMS template system uses syntax similar to Django, and the core tool for obtaining category details iscategoryDetailLabel. You can imagine it as an intelligent assistant, you tell it what field you want to see, and it can accurately extract the classification information of the current page.

In most cases, when you visit a category page, such as an article list page or a product list page,categoryDetailThe label will automatically identify the current category and extract the information you need. You usually don't need to specify the category ID extra, it can understand 'unspokenly'.

If indeed you need to retrieve *non-current page* specific category information, such as displaying the details of the "About Us" category in the sidebar, you can do so byidortoken(URL alias) to specify explicitly, for example:{% categoryDetail with name="Title" id="10" %}.

How to display the detailed information of categories?

categoryDetailThe usage of tags is usually:{% categoryDetail 变量名 with name="字段名称" %}Optional, the variable name is optional, if you want to output the result directly, you can omit it;If you want to store data in a variable for subsequent processing, you can define a variable name.nameThe parameter is the specific field you want to retrieve.

Here are some commonly used fields and their calling methods in the template:

  • Category Title (Title):This is the core display content of the category.

    <h1>{% categoryDetail with name="Title" %}</h1>
    
  • Category Link (Link):Used to generate a hyperlink to the current category page.

    <a href="{% categoryDetail with name="Link" %}">更多内容</a>
    
  • Category Description (Description) and Category Content (Content): DescriptionTypically a short category summary, suitable for use inmetaTag or the introduction at the top of the page.ContentIt is a more detailed classification introduction, which may contain rich text content.

    <p>{% categoryDetail with name="Description" %}</p>
    <div>
        {# 注意:Content字段可能包含HTML,需要使用|safe过滤器确保正确渲染 #}
        {%- categoryDetail categoryContent with name="Content" %}
        {{ categoryContent|safe }}
    </div>
    

    Here is a special reminder,ContentIf the field contains HTML tags, be sure to add them.|safeFilter, otherwise the HTML code will be escaped instead of rendered as page structure.

  • Image information (Logo, Thumb, Images):

    • LogoThis generally refers to the main image or large image of the category.
    • ThumbThis refers to the thumbnail of the category.
    • ImagesIf the category is set with multiple Banner images or group images, you can useImagesField gets an image array and displays it in a loop.
    {# 显示分类Logo大图 #}
    <img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}" />
    
    {# 显示分类Banner组图(如果有) #}
    {% categoryDetail categoryBanners with name="Images" %}
    {% if categoryBanners %} {# 检查是否有图片存在,避免空循环 #}
        <div class="category-banner-slider">
            {% for imgUrl in categoryBanners %}
                <img src="{{ imgUrl }}" alt="{% categoryDetail with name="Title" %}" />
            {% endfor %}
        </div>
    {% endif %}
    
  • Parent category ID (ParentId) and document count (ArchiveCount): ParentIdIt can help you build a more complex category navigation, such as displaying the parent category name of the current category.ArchiveCountIt will let you know how many articles or products are under the current category.

    {# 获取上级分类ID,并尝试获取其标题 #}
    {% set currentParentId = "" %}
    {% categoryDetail parentId with name="ParentId" %}{% set currentParentId = parentId %}
    {% if currentParentId and currentParentId != "0" %}
        <p>上级分类:<a href="{% categoryDetail with name="Link" id=currentParentId %}">{% categoryDetail with name="Title" id=currentParentId %}</a></p>
    {% endif %}
    
    <p>包含文章数:{% categoryDetail with name="ArchiveCount" %}</p>
    

Process custom category field

The 'Flexible Content Model' of AnQi CMS is a very powerful feature that allows you to add dedicated fields for different content types (such as articles, products, and custom models). If you also add custom fields to the category model, you can do so in the same way.categoryDetailtags to obtain.

Assuming you have added a category with the namecustom_banner_textyou can call it directly:

<p>自定义Banner文本:{% categoryDetail with name="custom_banner_text" %}</p>

If you want to loop through all custom fields, you can usename="Extra":

{% categoryDetail extras with name="Extra" %}
{% for field in extras %}
    <div>
        <strong>{{ field.Name }}:</strong>
        {# 注意:自定义字段的值也可能包含HTML,酌情使用|safe #}
        <span>{{ field.Value|safe }}</span>
    </div>
{% endfor %}

Combine an example: Display detailed information on the category list page

Let's see a complete example of displaying the current category details in a category list template. Suppose this isarticle/list.htmlTemplate:

{% extends 'base.html' %} {# 继承基础布局 #}

{% block main_content %}
    <div class="category-header">
        {# 显示当前分类的大标题 #}
        <h1>{% categoryDetail with name="Title" %}</h1>

        {# 如果有分类Logo,显示它 #}
        {% categoryDetail categoryLogo with name="Logo" %}
        {% if categoryLogo %}
            <img src="{{ categoryLogo }}" alt="{% categoryDetail with name="Title" %}" class="category-logo" />
        {% endif %}

        {# 显示分类的描述 #}
        <p class="category-description">{% categoryDetail with name="Description" %}</p>

        {# 显示分类的详细内容,并确保HTML正确渲染 #}
        <div class="category-full-content">
            {%- categoryDetail categoryContent with name="Content" %}
            {{ categoryContent|safe }}
        </div>

        {# 假设你有一个自定义字段 "category_slogan" #}
        {% categoryDetail categorySlogan with name="category_slogan" %}
        {% if categorySlogan %}
            <p class="category-slogan">“{{ categorySlogan }}”</p>
        {% endif %}
    </div>

    <div class="article-list">
        <h2>此分类下的文章</h2>
        {# 获取并展示当前分类下的文章列表 #}
        {% archiveList articles with type="page" limit="10" %}
            {% for article in articles %}
                <div class="article-item">
                    <h3><a href="{{ article.Link }}">{{ article.Title }}</a></h3>
                    <p>{{ article.Description }}</p>
                    <span>发布日期:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                    <span>阅读量:{{ article.Views }}</span>
                </div>
            {% empty %}
                <p>当前分类下还没有文章。</p>
            {% endfor %}
            {# 分页导航 #}
            {% pagination pages with show="5" %}
                {# 这里可以插入你的分页代码 #}
            {% endpagination %}
        {% endarchiveList %}
    </div>
{% endblock %}

By this example, we can see how to combinecategoryDetailthe information obtained fromarchiveListother tags to build a rich and functional classified page.

Summary

Of Security CMScategoryDetailTags are an indispensable tool for website content operators and template developers.It provides a concise way to have high control over category details, whether it's the basic title, description, or complex multi-image carousel and custom fields, it can be easily achieved.Make good use of these tags, which can help your website improve its information display and user experience.


Frequently Asked Questions (FAQ)

How do I get the name and link of the parent category on the current category page?

You first need to get the current category'sParentId. Then, you can use it againcategoryDetailthe tag, passing this inParentIdTo get the details of the parent category.

`twig {% categoryDetail currentCategory with name=“Id” %} {# Get current category ID #} {% categoryDetail parentId with name=“ParentId” id=currentCategory %} {# Get parent ID of current category #}

{% if parentId and parentId !="0" %}

<p>父级分类:<a href="{% categoryDetail with name="Link" id=parentId %}">{% categoryDetail with name="Title" id=parentId %}</a></p>

{% else %}

<p

Related articles

How to get the category list of a specified content model and display it in AnQiCMS?

In AnQiCMS, flexibly obtaining and displaying the category list of the specified content model is the key to building a clear website structure and a good user experience.Whether it is product display, article archive, or service introduction, the category list plays an important navigation role.AnQiCMS's powerful template tag system makes this process intuitive and efficient.

2025-11-08

How to use the breadcrumb navigation tag of AnQiCMS to display the current page path?

In website operation, a clear navigation path is crucial for user experience and search engine optimization (SEO).A Breadcrumb Navigation is an auxiliary tool that can significantly improve the usability of a website, providing a quick and convenient way for users to return to their previous page and clearly indicating their position on the current page.In AnQiCMS, implementing breadcrumb navigation is very simple and flexible.AnQiCMS provides us with a dedicated breadcrumb navigation tag `breadcrumb`, through it

2025-11-08

How to build and display a multi-level navigation menu in AnQiCMS template?

The website navigation is the first window for users to interact with the website. A clear and intuitive navigation system can greatly enhance the user experience and help visitors quickly find the information they need.AnQiCMS provides a flexible and powerful navigation management function, whether it is a simple single-level menu or a complex two-level, three-level, or even more hierarchical multi-level navigation, it can be easily realized.Next, we will learn in detail how to build and display multi-level navigation menus in AnQiCMS.## Backend Settings: The Foundation of Navigation Construction Navigation construction in AnQiCMS begins with careful configuration in the backend

2025-11-08

How to dynamically display the website's homepage TDK information in AnQiCMS?

The TDK of a website, which stands for Title (title), Description (description), and Keywords (keywords), is a basic element of Search Engine Optimization (SEO), which directly affects the display effect and user click intention of the website in the Search Engine Results Page (SERP).For the "face" of the website - the homepage, accurate and attractive TDK information is crucial.In AnQiCMS (AnQiCMS), managing and dynamically displaying the TDK information of the website homepage is a straightforward and efficient task

2025-11-08

How to display the list and links of all single pages in AnQiCMS template?

In AnQiCMS, wanting to display a list and links of all single pages in a website template is actually a very common requirement, such as you may want to place a 'site map' or 'quick link' area at the bottom of the website, or you may need to list all 'service items' single pages in the sidebar.AnQiCMS provides a simple and powerful template tag that allows you to easily achieve this.### Understanding Single Page and Its Role In AnQiCMS, a single page (Page) is usually used to publish content that is relatively fixed

2025-11-08

How to get and display the content and title of a specific single page in AnQiCMS?

In AnQiCMS, a single page is a very practical part of the website structure, usually used to display static content such as "About Us", "Contact Information", etc.As a content operator, you may often need to retrieve and display the content and titles of specific single pages at different locations on the website.AnQiCMS provides an intuitive and powerful template tag, making this process very simple. ### Understanding Single Page in AnQiCMS One of the design philosophies of AnQiCMS is the high customizability of content.

2025-11-08

How to retrieve a list of articles or products in AnQiCMS and support pagination display?

How to efficiently display articles or product lists in a content management system and provide users with a smooth pagination experience is a common concern for website operators.AnQiCMS is a system developed based on the Go language, which makes everything intuitive and efficient through its flexible and powerful template tag system.Next, we will discuss how to take advantage of the built-in features of AnQiCMS to easily implement the list display and pagination functions of articles or products.

2025-11-08

How to display the detailed content of a specified article or product in AnQiCMS?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides an intuitive way to manage and display various types of content.When you want to display a specific article, product details, or any independent content page created through a content model on a website, the core lies in using its powerful template tag features.AnQiCMS refers to the articles, products, and other independently displayed content on the website as 'documents' (archive).

2025-11-08