As an expert in the operation of AnQiCMS, I am well aware of the importance of classified information in constructing website structure and enhancing user experience.The AnQi CMS, with its intuitive and powerful template tag system, makes it extremely easy to obtain and display detailed information about categories.In order to optimize navigation, enrich page content, or improve SEO effect, accurately obtaining category names, descriptions, and links is an indispensable part of our daily operations.
The core of AnQi CMS lies in its flexible template tags, and for obtaining category information,categoryDetailThe tag is undoubtedly our main tool.This tag is specifically designed to extract the properties of a single category.It not only intelligently identifies and displays the detailed information of the current page category, but also supports obtaining data of any specific category by explicitly specifying the category ID or URL alias, which greatly enhances the flexibility and customization of content display.
To obtain the category ofnamewe can use it in the template.{% categoryDetail with name="Title" %}.This label will directly output the display name of the category.For example, on the "News Center{% categoryDetail with name="Title" id="10" %}. This 'name' is exactly the 'category name' field we set for the category in the 'document category' management interface of the AnQi CMS backend.
category ofdescriptionInformation is equally important for users to understand the classification content and for search engine optimization. Through{% categoryDetail with name="Description" %}We can easily obtain and display the introduction of the category.This corresponds to the 'Category Introduction' field in the background 'Document Category'.<meta name="description">The content of tags can enhance the crawling and ranking effect of search engines.
To get the classification oflinks(URL address) is the key to guiding users to browse and build website navigation. Using{% categoryDetail with name="Link" %}Label, you can get the complete URL of the category.The Anqi CMS will automatically generate and manage these links according to the static rules you configure in the background, as well as the 'Custom URL' field of the category.Whether it is a clear navigation menu or a classified jump in the article list, this link tag ensures the consistency of the website structure and the convenience of user access.
In addition to the above basic information,categoryDetailTags also provide the ability to obtain deeper classification metadata, such asParentId(Parent Category ID), This is crucial for building a clear hierarchy navigation menu or breadcrumb navigation. Moreover, you can easily obtain the visual elements of the category, such asLogo(Category thumbnail large image),Thumb(Category thumbnail) as wellImages(Category banner group image, usually an array of images, which can be used for carousel display). If your category model defines additional custom fields in the background, you can also specifyname="自定义字段名"In order to call these personalized data, thus achieving highly customized content display requirements.
For example, in your template, if you want to display all the core information of the current category, you can organize the code like this:
<div class="category-info-block">
<h1>{{ categoryDetail with name="Title" }}</h1>
<p>{{ categoryDetail with name="Description" }}</p>
<a href="{{ categoryDetail with name="Link" }}" title="更多关于{{ categoryDetail with name="Title" }}的内容">探索更多</a>
{% if categoryDetail with name="Logo" %}
<img src="{{ categoryDetail with name="Logo" }}" alt="{{ categoryDetail with name="Title" }}" class="category-logo" />
{% endif %}
</div>
Provided by Anqi CMScategoryDetailLabel, website operators can manage and display categorized content in an extremely flexible and efficient manner.This not only simplifies the template development process, but more importantly, it empowers us to build websites with clear structure, rich content, and SEO-friendly, thereby better serving our users and operational goals.
Frequently Asked Questions (FAQ)
How can I get and display the names and links of multiple categories in a loop without entering the category detail page? Answer:You can use
categoryListtag to get a collection of categories. For example,{% categoryList categories with moduleId="1" parentId="0" %}Get all top-level categories under the article model. In{% for item in categories %}loop, you can access it directly through{{ item.Title }}Get the category name and pass through{{ item.Link }}Get the category link. This method is suitable for building the main navigation menu or sidebar category list without using it separately for each category.categoryDetail.Ask: How can I call the Banner image and thumbnail images uploaded in the background in the front-end template? Answer:The Anqi CMS supports configuring Banner images and thumbnails for categories. To get the Banner image group for a category, you can use
{% categoryDetail categoryImages with name="Images" %}It will return an array of image URLs, which you can iterate over in the template to display these images. The thumbnails for categories can be accessed through{% categoryDetail with name="Logo" %}(usually refers to the large image) or{% categoryDetail with name="Thumb" %}(referring to the cropped or compressed thumbnail) to obtain.Question: If I add custom fields for categories in the background, how can I display these custom information in the frontend template? Answer:After you add custom fields to a category model in the background "Content Model", the values of these fields can also be accessed through
categoryDetailInvoke a label. For example, if you define a custom field named "Color" for categories, you can use it in the template.{% categoryDetail with name="颜色" %}Display the color value corresponding to the category. If you need to cycle through all custom fields, you can first use{% categoryDetail extras with name="Extra" %}Get all custom fields as a collection, and then in aforTraverse in a loopextrasAccess a variable{{ field.Name }}and{{ field.Value }}To display field names and values.