How to get and display detailed information of a specified category in AnQiCMS template?

Calendar 👁️ 54

As an experienced CMS website operation personnel in the information security field, I know that it is crucial to display content efficiently and accurately in templates for the attractiveness and SEO performance of the website.Category information is the core of website architecture, which can accurately obtain and present on the front-end page, not only improving user experience but also providing a clear structure for search engine crawling.Today, let's discuss in detail how to obtain and display the detailed information of a specified category in the Anqi CMS template.

Understanding AnQiCMS template and content display basics

The Anqi CMS adopts syntax similar to the Django template engine, allowing us to dynamically retrieve and display website data through simple tags. Template files are usually named with.htmlWith suffix and using double curly braces{{变量}}To output variable values, while logical control and data retrieval are through single curly braces and percentage signs{% 标签 %}To implement. Understanding these basic conventions is the premise of building dynamic pages when handling classification information.Ensure that template files are uniformly encoded in UTF-8 to avoid potential garbled code issues.

The core to get details of a specified category:categoryDetailTag

In AnQi CMS, to obtain the detailed information of the category, we mainly rely oncategoryDetailThe tag is very flexible, it can automatically identify the classification information of the current page, and can also obtain data of any classification by explicitly specifying parameters.

Generally, when you visit a category list page (such as文章模型/list-分类ID.html),categoryDetailtags can be automatically recognized without any parameters and provide detailed information about the current category.

However, we often encounter the need to display information about a specific category on non-category list pages (such as the homepage, article detail page, or custom page), or to retrieve and display information about other specific categories within a category list. In this case,categoryDetaillabel'sidortokenParameters are particularly crucial.

Specify the category by category ID (id) or URL alias (token) to specify the category

To get the detailed information of the specified category, you cancategoryDetailUsed in tagsidSpecify the numeric ID of the category or usetokenSpecify the URL alias of the category (usually the pinyin or a custom English alias of the category name).

For example, if you want to get the ID of1category title:

<div>分类标题:{% categoryDetail with name="Title" id="1" %}</div>

If you know the URL alias of a category isabout-usand you want to get its description:

<div>分类描述:{% categoryDetail with name="Description" token="about-us" %}</div>

In this way, you can accurately call the required classification information at any location on the website. Moreover, in a multi-site management environment, if you need to call classification information under other sites, you can also usesiteIdSpecify the corresponding site ID with the parameter.

Display detailed information fields of the category.

categoryDetailTags support throughnameSpecify the specific field to be retrieved. The following are some commonly used fields and their calling methods in the template:

  • Category ID (Id):Used to obtain the unique identifier for the category.

    <div>分类ID:{% categoryDetail with name="Id" id="1" %}</div>
    
  • Category title (Title):Get the category name, usually used to display on the page.

    <h1>{% categoryDetail with name="Title" id="1" %}</h1>
    
  • Category link (Link):Get the URL address of the category page. This is very useful for building navigation or 'View More' links.

    <a href="{% categoryDetail with name="Link" id="1" %}">访问{% categoryDetail with name="Title" id="1" %}</a>
    
  • Category description (Description):Get a brief introduction of the category, often used for SEO meta description or the introduction on the category page.

    <p>{% categoryDetail with name="Description" id="1" %}</p>
    
  • Category content (Content):If the category has detailed content in the background (such as description text), it can be obtained through this field. Please note that if the content contains HTML tags, it may be necessary to use|safeA filter to prevent automatic escaping.

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

    Hererender=trueThe parameter indicates that if the content is in Markdown format, it will be automatically converted to HTML.

  • Parent category ID (ParentId):Get the ID of the parent category of the current category, which is very useful for building multi-level category navigation or breadcrumbs.

    <div>上级分类ID:{% categoryDetail with name="ParentId" id="1" %}</div>
    
  • Category thumbnail (Thumb) and large image (Logo):If the category is set with an image, you can obtain its URL through these two fields.

    <img src="{% categoryDetail with name="Thumb" id="1" %}" alt="{% categoryDetail with name="Title" id="1" %}" />
    
  • Category Banner Group (Images):If the category is configured with multiple Banner images,ImagesThe field will return an array of image URLs, you need to useforloop to traverse and display them.

    {% categoryDetail categoryBanners with name="Images" id="1" %}
    <div class="category-banner-slider">
        {% for imageUrl in categoryBanners %}
            <img src="{{ imageUrl }}" alt="分类横幅图片" />
        {% endfor %}
    </div>
    
  • Number of documents in category (ArchiveCount):Displays the number of documents included in the category, helping users understand the richness of the category content.

    <div>该分类包含文章:{% categoryDetail with name="ArchiveCount" id="1" %}篇</div>
    
  • Custom field:In AnQi CMS backend, you can customize additional fields for the content model. If these custom fields are also applied to categories, you can go throughnameThe parameter is called directly, for example, if you have a custom field namedcategory_icon: custom field

    <i class="icon">{% categoryDetail with name="category_icon" id="1" %}</i>
    

    Or, if you want to loop through all the custom fields, you can useExtraField:

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

Combine other tags to achieve richer display

categoryDetailThe power of the tag lies in its ability to seamlessly integrate with other secure CMS tags, building complex and dynamic page layouts. For example, on a category detail page, you can first obtain the details of the current category, then usearchiveListLabel, and utilizecategoryDetailGet the category ID to filter and display the article list under the category.

{# 假设这是文章详情页,需要获取其分类的信息并显示该分类下的其他文章 #}
{% archiveDetail currentArchive with name="CategoryId" %} {# 获取当前文章的分类ID #}

<div class="category-info">
    <h2>分类名称: {% categoryDetail with name="Title" id=currentArchive %}</h2>
    <p>分类描述: {% categoryDetail with name="Description" id=currentArchive %}</p>
    <a href="{% categoryDetail with name="Link" id=currentArchive %}">进入分类页面</a>
</div>

<div class="related-articles">
    <h3>{{% categoryDetail with name="Title" id=currentArchive %}} 下的其他文章</h3>
    {% archiveList relatedArticles with categoryId=currentArchive type="list" limit="5" %}
        {% for article in relatedArticles %}
            <a href="{{ article.Link }}">{{ article.Title }}</a><br/>
        {% empty %}
            暂无其他文章。
        {% endfor %}
    {% endarchiveList %}
</div>

By this combination, you can easily create content displays with high relevance and dynamism, greatly enhancing the operational efficiency and user experience of the website.

Summary

Of Security CMScategoryDetailTags are powerful tools for retrieving and displaying information about specified categories. Whether it is throughidortokenSpecify precisely or combine other tags to implement complex layouts, it can help you flexibly control the presentation of categorized content in the template.Mastery of this tag's usage will enrich your website content, enhance interactivity, and better serve your users and business objectives.


Frequently Asked Questions

What will the template display if the specified category ID or URL alias does not exist?

IfcategoryDetailLabel specifiedidortokenThe category does not exist, this tag usually will not output any content.This means that the relevant area will remain blank or not displayed on the page.{% if categoryTitle %}Handle this situation elegantly to avoid empty titles or links.

How to get and display a list of all subcategories of a category in the template?

You can usecategoryListLabel collaborationcategoryDetailComplete the tag. First, throughcategoryDetailGet the parent category ID, then use this ID ascategoryListlabel'sparentIdparameter, you can get and loop to display all the subcategories under it.

{# 假设当前在父分类页面,获取其ID #}
{% categoryDetail currentCategoryId with name="Id" %}
<h3>子分类列表</h3>
<ul>
    {% categoryList subCategories with parentId=currentCategoryId %}
        {% for subCategory in subCategories %}
            <li><a href="{{ subCategory.Link }}">{{ subCategory.Title }}</a></li>
        {% endfor %}
    {% empty %}
        <li>该分类暂无子分类。</li>
    {% endcategoryList %}
</ul>

Related articles

How to list category information in AnQiCMS templates by module or parent relationship?

A detailed guide to listing category information by module or parent relationship in AnQiCMS templates As an experienced AnQiCMS website operator, I know the importance of content organization.A clear, easy-to-navigate classification system not only improves user experience, but is also the foundation of SEO optimization.AnQi CMS, with its flexible content model and powerful template tag system, provides us with multiple ways to display category information in website templates according to module or parent-child relationship.This article will delve into how to make use of these features to build an efficient classification list.###

2025-11-06

How to generate breadcrumb navigation path in AnQiCMS templates?

As an experienced CMS website operation personnel, I am well aware of the importance of a clear and efficient website navigation system for user experience and search engine optimization (SEO).Breadcrumbs navigation is an important part of website auxiliary navigation, which can intuitively show the user's position on the website and provide a convenient return path.The AnQi CMS with its flexible template engine makes it easy and efficient to generate breadcrumb navigation in website templates.

2025-11-06

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

Hello, I am the familiar Anqi CMS website operation veteran that you know.Navigation menus are of great importance in daily website maintenance and content optimization, as they are not only guides for users to browse the website but also crucial for search engines to understand the website structure.Today, let's delve into how to build a flexible and efficient multi-level navigation menu in the AnQiCMS template.

2025-11-06

How to dynamically set the content of the `<title>`, `<meta keywords>`, and `<meta description>` tags for AnQiCMS pages?

As an experienced security CMS website operator, I know that website SEO optimization is the core work to attract and retain users, and to enhance the visibility of the website.It is crucial to accurately set the <title>, <meta keywords>, and <meta description> tags for each page (collectively known as TDK, i.e., Title, Description, Keywords).The AnQi CMS was designed with SEO-friendliness in mind from the outset

2025-11-06

How to list all or specified types of single pages in AnQiCMS template?

Managing and displaying single pages in AnQiCMS is a common requirement for website operation, especially for static content such as 'About Us', 'Contact Information', and 'Terms of Service'.As an experienced AnQiCMS operator, I know that efficient use of template tags can greatly enhance the flexibility of content publishing and the maintenance efficiency of the website.This article will detail how to list all or specified types of single pages in the AnQiCMS template.### Understanding the Single Page Mechanism of AnQiCMS In AnQiCMS, a single page (Single

2025-11-06

How to display the detailed content of a specified single page in AnQiCMS template?

In AnQiCMS website operation, the Single Page (Page) feature is a very practical module, which allows us to create and manage static pages independent of dynamic content such as articles or products, such as "About Us", "Contact Information", or "Service Introduction" and so on.These pages usually contain relatively fixed and important information, which needs to be presented to visitors in a clear and direct manner.As a senior operator of AnQiCMS, I know how to effectively use the template mechanism to accurately control the display of these single pages to meet the diverse design and content needs.

2025-11-06

How to filter and display the document list in AnQiCMS template according to categories, models, recommended attributes, etc.

As an experienced AnQiCMS website operations manager, I fully understand the importance of efficient content management and flexible display.In AnQiCMS, the filtering and display of document lists are indispensable functions for building dynamic websites.Whether it is to display the latest articles under a specific category, or to differentiate products and news according to the content model, or to highlight recommended content, AnQiCMS's powerful template tags can help us easily achieve these needs.

2025-11-06

How to get the detailed information of the current document in AnQiCMS template (such as title, content, thumbnail)?

As an experienced AnQiCMS website operator, I am well aware of the importance of flexibly obtaining and displaying content in templates.AnQiCMS is a powerful template engine that makes content creation, editing, and publishing efficient and convenient.Today, we will delve into how to obtain detailed information about the current document in the AnQiCMS template, such as the title, content, and thumbnail, to help you better customize the front-end display of the website.

2025-11-06