How to accurately call the detailed information of a specified category through the category ID or category alias (token)?

Calendar 👁️ 73

As an experienced website operations expert, I know that being able to call data accurately and flexibly is the key to improving operational efficiency and website performance.AnQiCMS (AnQiCMS) relies on its powerful template tag system to provide us with many conveniences, especially in calling detailed category information, whether through category ID or category alias (token), it can achieve precise operations.

Today, let's delve deeply into how to obtain and display detailed information about specified categories in Anqi CMS through these two methods.

Understand the categories and identifiers in Anqi CMS.

In Anqi CMS, content classification is the core framework of website content organization.Whether it is an article, product, or other custom content model, it must be categorized.Each category has some unique identifiers so that the system and template can accurately identify and call them:

  1. Category ID (ID)This is a unique identifier automatically generated by the system. It is the most direct and stable proof of classification, usually visible in the background management interface or database.
  2. Category Alias (Token): To better support search engine optimization (SEO) and improve the readability of URLs, Anqi CMS allows us to set a unique English alias for categories. This alias will appear in the URL (if the pseudo-static rules are configured properly), for example,/category/newsofnewsThis is an alias. It is more semantically meaningful and friendly to users and search engines.

In the practice of content operation, we often need to display the title, description, link, and even the number of documents or custom fields contained in the category based on a specific category ID or alias. At this time, Anqi CMS providescategoryDetailTemplate tags have become our powerful assistants.

Core tool:categoryDetailTemplate Tag

categoryDetailThe tag is a special tag in AnQi CMS used to retrieve detailed information of a single category.It allows us to specify exactly which category's specific information we want to retrieve by category ID or alias.

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

Let's break down the various parts of this tag:

  • 变量名称This is an optional parameter. If you want to assign the obtained category information to a variable for multiple use in the template or for logical judgment, you can define a variable name here.If not defined, the label will output the result directly.
  • name="字段名称"This is the most critical part, it specifies which specific field of the category you want to retrieve. For example,name="Title"It will retrieve the title of the category,name="Description"It will retrieve the description of the category.
  • id="分类ID"Through the numeric ID of the category, specify the target category. For example,id="5"Means to obtain the category information with ID 5.
  • token="分类别名": Specify the target category by the alias (English token). For example,token="products"indicates to get the alias namedproductscategory information.
  • siteId="站点ID"If you have enabled the multi-site feature and want to call data from other sites, you can specify the site ID through this parameter.In most cases, this parameter does not need to be filled in, the system will default to calling the data of the current site.

nameList of category fields that can be called by parameters:

Of Security CMScategoryDetailTags support calling the rich information of categories, commonly including:

  • Id: The unique digital ID of the category.
  • Title: The name or title of the category.
  • Link: The URL link of the category.
  • Description: Brief category description, often used for SEO.
  • Content: Detailed category content, which can include HTML.
  • ParentId: Parent category ID, used to build hierarchical relationships.
  • Logo: The category cover large image address.
  • Thumb: The category thumbnail image address.
  • Images: The category Banner image group (usually an array of images).
  • ArchiveCountThe number of documents (content) under the category.
  • 后台自定义字段名称If you add custom fields to the category model in the background, you can directlyname="你的自定义字段名"call its value.

Practice: Accurately Call Various Information

Next, let's look at how to flexibly use some specific code examples.categoryDetail.

Scenario one: Call the title and link of a specific category on a non-category page

Assuming you are on the homepage or a specific article detail page, you need to display the title of the specific category 'Product Category' and generate a link for it. We know that the ID of 'Product Category' is2alias isproducts.

call by ID:

{% set productCategoryTitle = "" %}
{% categoryDetail productCategoryTitle with name="Title" id="2" %}{# 将ID为2的分类标题赋值给productCategoryTitle变量 #}

{% set productCategoryLink = "" %}
{% categoryDetail productCategoryLink with name="Link" id="2" %}{# 将ID为2的分类链接赋值给productCategoryLink变量 #}

<p>前往 <a href="{{ productCategoryLink }}">{{ productCategoryTitle }}</a> 页面。</p>

or, if you don't need to assign to a variable, output directly:

<p>前往 <a href="{% categoryDetail with name='Link' id='2' %}">{% categoryDetail with name='Title' id='2' %}</a> 页面。</p>

call by alias (token):

{% set productCategoryTitleByToken = "" %}
{% categoryDetail productCategoryTitleByToken with name="Title" token="products" %}

{% set productCategoryLinkByToken = "" %}
{% categoryDetail productCategoryLinkByToken with name="Link" token="products" %}

<p>探索我们的 <a href="{{ productCategoryLinkByToken }}">{{ productCategoryTitleByToken }}</a>。</p>

Scenario two: Get the category description information for SEO meta tags

Assuming we need in the customized_header.htmltemplate, according to the current page category alias (assuming thatnews) to get its description information, fill in to<meta name="description">.

”`twig <meta name=“description” content=“{% categoryDetail with name=“Description

Related articles

What is the main purpose and application scenario of the 'Category Details Label' in Anqi CMS?

As an experienced website operations expert, I know that how to flexibly and efficiently display information in a content management system is the key to the success of the website.AnQiCMS (AnQiCMS) provides many conveniences in this aspect with its powerful functions.Today, let's delve deeply into a very practical and powerful template tag in Anqi CMS, the **category detail tag (`categoryDetail`)**, and see how it plays a core role in content operation.

2025-11-06

How is the loading speed of AnQiCMS comment captcha under low bandwidth network conditions, can it be optimized?

As an experienced website operations expert, I know that it is crucial to achieve a balance between user experience and website security in an increasingly complex network environment.AnQiCMS (AnQiCMS) has won the favor of many users in the content management field with its high-performance architecture based on the Go language.Today, let's delve deeply into a frequently discussed issue in actual operation: 'How fast does AnQiCMS comment captcha load in low bandwidth network environment, can it be optimized?'

2025-11-06

How does the backend program handle the `captcha` field of AnQiCMS when submitting?

As an experienced website operations expert, I am very familiar with the fact that every seemingly small field in a content management system carries important functions and security responsibilities.AnQiCMS (AnQiCMS) is an efficient and secure system with Go language as its core, and its captcha mechanism design naturally reflects this concept.Today, let's delve into how the backend program cleverly handles the `name="captcha"` field in the form submission in AnQiCMS.

2025-11-06

After using the AnQiCMS built-in message captcha, should you still consider integrating a third-party anti-spam comment service?

As an experienced website operations expert, I am well aware that how to efficiently manage website content and ensure its security is one of the core challenges in an increasingly complex network environment.AnQiCMS (AnQiCMS) provides a solid foundation for our content management work with its lightweight, efficient, secure, and easy-to-use features.In daily operations, we often encounter an important issue regarding the quality of user interaction: spam in comments.

2025-11-06

What is the tag syntax for getting the category title, category link, and category description on the current page?

As an experienced website operations expert, I know that in an efficient content management system like AnQiCMS, it is crucial to flexibly call page data to build a user-friendly and SEO-friendly website.Today, we will focus on a common and core requirement: how to accurately obtain the category title, category link, and category description of the current page in Anqi CMS template.

2025-11-06

Can the category detail tag display the complete content (Content)? How can you ensure correct rendering?

As an experienced website operations expert, I know that how to flexibly and accurately display content in a content management system is the key to operational success.TodayHow to operate to ensure correct rendering?

2025-11-06

Markdown formatted category content, how to automatically render it into HTML format through category detail tags?

In the daily operation of the AnQiCMS website, content creators often need to find a balance between creative efficiency and the final presentation effect.Markdown format, with its concise and intuitive syntax, has undoubtedly become the preferred tool for many content editors.How can one elegantly and efficiently render Markdown-written categorized content into browser-readable HTML format in the powerful AnQiCMS content management system?

2025-11-06

How to get the SEO title, keywords, and description of a category to optimize the search engine inclusion of the category page?

In the vast realm of website operations, category pages are like lighthouses of navigation, guiding users to the content they are interested in, while also showing search engines the organization and depth of the website's content.A well-optimized category page, which can not only significantly improve user experience, but is also the key to gaining search engine favor and winning natural traffic.

2025-11-06