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 provides us with many conveniences with its powerful template tag system, especially in calling detailed information of categories, whether through category ID or category alias (token), it can achieve accurate operations.

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

Understand the categories and their identifiers in Anqi CMS

In AnQi CMS, content categories are the core framework of website content organization.Whether it is an article, product, or other custom content model, it needs to belong to a specific category.

  1. Category ID (ID)This is a unique identifier automatically generated by the system. It is the most direct and stable form of identification for 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 correctly), for example/category/newsofnewsIt is an alias. It is more semantically meaningful and friendlier 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 a category based on a specific category ID or alias. At this time, the Anqi CMS providescategoryDetailTemplate tags have become our powerful assistants.

core tools:categoryDetailTemplate tags

categoryDetailThe tag is a special tag used in AnQi CMS to obtain detailed information of a single category.It allows us to precisely specify which specific information of a category to retrieve by its category ID or alias.

Its basic usage method is as follows:{% 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 uses in the template or for logical judgment, you can define a variable name here.If not defined, the tag will output the result directly.
  • name="字段名称"This is the most critical part, specifying which specific field of the category you want to retrieve. For example,name="Title"will retrieve the title of the category,name="Description"will retrieve the description of the category.
  • id="分类ID"Specify the target category through the numeric ID of the classification. For example,id="5"Represents retrieving the category information with ID 5.
  • token="分类别名": Specify the target category through the alias (English token) of the classification. For example,token="products"represents getting the alias ofproductscategory 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 with parameters:

Anqi CMS'scategoryDetailThe label supports calling the rich information of categories, commonly including:.

  • IdThe unique digital ID of the category.
  • TitleThe name or title of the category.
  • LinkThe URL link of the category.
  • Description【en】Category brief description, often used for SEO.
  • Content【en】Category detailed content, which can include HTML.
  • ParentId【en】Parent category ID, used to build hierarchical relationships.
  • Logo: The cover image address of the category.
  • Thumb: The thumbnail image address of the category.
  • Images: The Banner image group of the category (usually an array of images).
  • ArchiveCountThe number of documents (content) under this category.
  • 后台自定义字段名称If you have added custom fields to the category model in the backend, you can directly accessname="你的自定义字段名"to call its value.

Practical Exercise: Precise Invocation of Various Information

Next, let's look at how to flexibly apply by some specific code examplescategoryDetailLabel.

Scene one: Call the title and link of a specific category from a non-categorized page

Assuming you are on the homepage or a specific article detail page, you need to display the title of the "Product Category" specific category and generate a link for it. We know that the "Product Category" ID 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 a value 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>

Scene two: Obtain the description information of the category for SEO meta tags

Suppose we need to be in the custom_header.htmltemplate, based on the alias of the current page category (supposed to benewsTo obtain its description information, fill in<meta name="description">.

`twig