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:
- 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.
- 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