How to obtain all the details of the category owned by the document details page?
How to delve deeper into the details of the AnQi CMS document detail page to obtain all the information of the category it belongs to?
In website content operation, the document detail page is not just about displaying articles or products, it often needs to establish a connection with a broader content system, such as displaying detailed information about the categories it belongs to.This not only enhances the user experience, guides users to discover more related content, but also helps improve the internal link structure and SEO performance of the website.As an experienced website operations expert, I know that AnQiCMS (AnQiCMS) is powerful and flexible in handling such needs.Today, let's discuss in detail how to elegantly and efficiently obtain all the detailed information of the category in the document detail page of AnQi CMS.
Understanding the context of the document detail page
When a user visits a document page (such as an article or a product detail), the Anqi CMS template system will load the corresponding document detail page template. In this template, all the information of the current document has been presented in aarchiveIn the form of an object, or byarchiveDetailTags that you can call at any time. The key to obtaining the information of its category lies in using thisarchiveThe category ID contained in the object.
The most direct way: usearchive.Categoryobject
AnQi CMS took full consideration of content relevance during design, therefore, in the document detail page, it is usually possible to directly througharchiveAn object accesses its category details. This means that the document object itself may already carry the complete data of its category.
Assuming you have already obtained the current document in the template'sarchiveobject (which is usually available by default on the document details page, or you can get one named by{% archiveDetail currentArchive %}the tagcurrentArchiveThe document object, you can directly accesscurrentArchive.Categoryto access the various fields of the category.
For example, if you want to display the title, link, and description of the category, you can operate like this:
{# 假设当前文档对象已命名为 'archive' 或 'currentArchive' #}
{% if archive.Category %}
<p>所属分类:<a href="{{ archive.Category.Link }}">{{ archive.Category.Title }}</a></p>
<p>分类描述:{{ archive.Category.Description }}</p>
{# 如果分类有缩略图或Logo,也可以直接调用 #}
{% if archive.Category.Logo %}
<img src="{{ archive.Category.Logo }}" alt="{{ archive.Category.Title }}" />
{% endif %}
{% endif %}
This method is very concise and efficient, it saves the additional tag call and parameter passing, and is the most recommended way to obtain information about the document's category.
Precise query and customization: usingcategoryDetailTag
Althougharchive.CategoryProvided great convenience, but in some cases, you may need to finely control which classification fields to obtain, or you want to obtain the current document classification ofCustom fieldThis is where the AnQi CMS providedcategoryDetaillabels can be put to use.
categoryDetailThe label allows you to accurately query the details of the category based on the category ID. And this category ID, we can also obtain from the current document'sarchive.CategoryIdfield.
Its basic usage method is{% categoryDetail 变量名称 with id="分类ID" %}.
For example, if you want to get the title of the category of the current document and the custom "category banner image" field (assuming you have added a category model named in the background)banner_imageYour custom field
{# 假设当前文档对象为 'archive' #}
{% if archive.CategoryId %}
{% set currentCategoryId = archive.CategoryId %} {# 将分类ID赋值给一个变量,方便后续使用 #}
<p>通过categoryDetail获取分类标题:{% categoryDetail with name='Title' id=currentCategoryId %}</p>
<p>通过categoryDetail获取分类链接:<a href="{% categoryDetail with name='Link' id=currentCategoryId %}">查看更多</a></p>
{# 进一步获取分类的自定义字段,例如“分类横幅图” #}
{% categoryDetail categoryBanner with name='banner_image' id=currentCategoryId %}
{% if categoryBanner %}
<img src="{{ categoryBanner }}" alt="{% categoryDetail with name='Title' id=currentCategoryId %} 的横幅图" />
{% endif %}
{# 如果您想一次性获取分类的所有自定义字段并遍历显示 #}
{% categoryDetail categoryExtras with name="Extra" id=currentCategoryId %}
{% if categoryExtras %}
<h4>分类自定义属性:</h4>
<ul>
{% for field in categoryExtras %}
<li>{{ field.Name }}:{{ field.Value }}</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
In the above example, we first go through{% set currentCategoryId = archive.CategoryId %}Store the current document's category ID in a temporary variable. Then, we can use it repeatedly.categoryDetaillabel and pass thisidparameter to retrieve the required category information, including the standardTitle/Linkas well as throughname='banner_image'orname='Extra'custom field obtained.
Comprehensive application example: building a complete classification information block
Now, let's integrate these knowledge points to build a block that displays the complete information of the category on the document detail page.
`twig
{# 获取当前文档对象 #}
{% archiveDetail currentArchive %}
<header>
<h1>{{ currentArchive.Title }}</h1>
<div class="meta-info">
发布于:{{ stampToDate(currentArchive.CreatedTime, "2006年01月02日") }} | 浏览量:{{ currentArchive.Views }}
</div>
</header>
<section class="category-context">
<h2>所属分类信息</h2>
{% if currentArchive.Category %}
<div class="category-card">
<a href="{{ currentArchive.Category.Link }}" class="category-title">
<h3>{{ currentArchive.Category.Title }}</h3>
</a>
{% if currentArchive.Category.Logo %}
<img src="{{ currentArchive.Category.Logo
Related articles
How to format the display of the release and update time of AnQiCMS documents?
As an experienced website operations expert, I am well aware that the accuracy and readability of time in content display are crucial for user experience and Search Engine Optimization (SEO).AnQiCMS as an efficient and flexible content management system provides a very convenient way to control the display format of the publication and update time of articles.This article will focus on how AnQiCMS formats and displays the publication and update times of documents, and will explain the secrets and practical skills in detail.
2025-11-06How to display multiple cover group images in a document detail page?
As an expert who deeply understands website operation, I know that high-quality, visually appealing content is the key to retaining users and enhancing the value of the website.AnQiCMS (AnQiCMS) is a powerful content management system that provides great flexibility in content presentation.Today, let's delve into a common need: how to cleverly loop multiple cover group images on the document detail page to make the content more expressive. --- ## Secure CMS: Delicate Presentation!A guide to displaying multiple cover group images in document detail pages In the era of content is king
2025-11-06How does Anqi CMS display the cover image and thumbnail of the document?
As an experienced website operations expert, I know the importance of a high-quality cover image and a proper thumbnail for the attractiveness of the website, user experience, and even search engine optimization (SEO).AnQiCMS (AnQiCMS) deeply understands this, and its design in image processing and display is not only powerful in function but also takes into account the convenience of operation and flexibility of display. Let's delve into how Anqi CMS cleverly displays document cover images and thumbnails.
2025-11-06How to set and call the recommended attribute (Flag) of the document in AnQiCMS?
## AnQiCMS High-efficiency Operation Manual: Mastering the Settings and Calls of Document Recommendation Attributes (Flag) As an experienced website operations expert, I am well aware that how to make your high-quality content stand out in the vast sea of digital content and accurately reach your target users is the key to success.AnQiCMS as a powerful content management system, its built-in "Flag" feature is a powerful tool to help content achieve fine-grained operation.It can not only help you flexibly organize and display content, but also effectively enhance the exposure and user perception of the content. Today
2025-11-06How to call custom document fields (such as author, price) and display them in AnQi CMS?
AnQi CMS offers powerful content management capabilities with its excellent flexibility and customizability to website operators.In the daily operation of websites, we often encounter situations where standard fields (such as titles, content, and publication time) cannot fully meet the needs of specific content display.At this moment, custom document fields have become our powerful assistants, for example, adding "author" information to an article, or supplementing "price" attributes to a product, and so on.How can we flexibly call these custom fields and display them on the website page in Anqi CMS today?
2025-11-06Unveiling AnQi CMS: How Markdown content is beautifully presented on your website?
AnQi CMS is an efficient content management system that knows well the pursuit of convenience by content creators.Markdown is a lightweight markup language that is favored by content editors for its concise, easy-to-learn, and clear formatting features.How can we ensure that the wonderful content you write in Markdown in Anqi CMS can be perfectly converted into browser-readable HTML and displayed on the front-end page without any loss?
2025-11-06How to get the list of articles under a specified category in AnQiCMS?
## Easily retrieve the list of articles under a specified category in AnQiCMS As an experienced website operations expert, I fully understand the core value of a content management system (CMS) lies in its ability to organize and present content.Among many features, how to efficiently extract and display articles from a specific category is an indispensable part of the daily work of website operators.Today, let's delve deep into how AnQiCMS can help you achieve this goal, making technical details intuitive and easy to understand.
2025-11-06How to implement pagination and page number display for article lists in AnQi CMS?
As an experienced website operations expert, I am well aware of the crucial role of a powerful and easy-to-use content management system for the success of a website.AnQiCMS (AnQiCMS) boasts a high-performance architecture based on the Go language and flexible template mechanism, providing an excellent experience in content publishing and management.Among them, efficiently displaying a large amount of content, especially implementing the pagination function of the article list, is an indispensable factor in improving user experience and website SEO performance.Today, let's delve deeply into how AnQi CMS cleverly implements this feature and demonstrates friendly page navigation.--- ##
2025-11-06