As an experienced website operations expert, I know that how to efficiently and accurately extract and display data in a content management system is the foundation of website success.AnQiCMS as an enterprise-level content management system based on the Go language, its concise and efficient template engine is deeply appreciated by me.categoryListIn the loopitem.Titleanditem.LinkWhat does it represent, and how should we elegantly present it in the template?
UnveilingcategoryListThe core element in the loop:item.TitleWithitem.Link
In the template world of AnQiCMS,categoryListTags are the core tools for obtaining and displaying website classification information. Whether it is building the main navigation menu, sidebar classification list, or the classification entrance on the homepage, categoryListThey are indispensable tools for us.When you use this tag to iterate over category data, it will return a collection containing multiple "items".item.Titleanditem.LinkThese are the most basic and most important properties of these categories.
item.Title: The face of the category.
We can imagine thatitem.TitleIt represents the 'face of the category' in the current loop.Category display name.This name is the most intuitive text information for users, such as 'Company News', 'Product Center', 'Contact Us', and so on.It is commonly used for navigation bar text, category list titles, or any place where category names need to be displayed to visitors.
In AnQiCMS,item.TitleThe value directly comes from the "Category Name" you set for this category in the backend.It is not only the basis for user identification classification, but also one of the key texts that search engines understand the content of the page.Therefore, writing clear and descriptive category titles is crucial for enhancing user experience and SEO performance.
you need to output it in the templateitem.Title, you just need to place it in double curly braces{{ }}. For example:
{{ item.Title }}
This will directly display the name of the category pointed to by the current loop on the webpage.
item.Link: The bridge to the content
If we sayitem.Titleis the name of the category, thenitem.Linkit is the path to this category page.Unique PathIt is also the URL address of the category. It is responsible for guiding users to click and jump to the content list page under the category, for example, clicking 'Product Center' will enter the page that displays all products.
item.LinkThe value is dynamically generated by AnQiCMS based on the pseudo-static rules, category aliases, and other settings of your website. It is usually a friendly URL that has been optimized for SEO. A well-structured and semantically clearitem.LinkIt plays a decisive role in the overall architecture of the website, user navigation experience, and search engine crawling.
Output in the templateitem.LinkWhen, its most common application scenario is as HTML<a>TagshrefProperty value, categorize the name (item.Title) into a clickable link. For example:
<a href="{{ item.Link }}">...</a>
Combine both: build a navigable category list
Whenitem.Titleanditem.LinkWhen used together, they form the most fundamental and important navigation elements of a website. You can use a simpleforLoop, dynamically output all categories and their links as the navigation structure of the website.
Here is a typicalcategoryListLoop combineditem.Titleanditem.LinkThis example demonstrates how to create a basic categorized navigation list:
{% categoryList categories with moduleId="1" parentId="0" %}
<ul>
{% for item in categories %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
In this code block:
{% categoryList categories with moduleId="1" parentId="0" %}This line of code tells AnQiCMS to retrieve all top-level categories under the model with ID 1 (usually the article model).parentId="0"), and assign these category data tocategoriesa variable.{% for item in categories %}We continue to traversecategoriesthis collection, each loop will assign a category of data toitema variable.<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>In the loop body, we willitem.Linkas<a>Tagshrefattributes,item.TitleAs the link display text. In this way, each category is rendered as a clickable navigation item, which can jump to the corresponding category page when clicked.
This way, AnQiCMS allows template developers to build complex website structures with high flexibility and efficiency, while ensuring accessibility and SEO-friendliness.
Summary
Understanding in AnQiCMS template development,categoryListin the loop,item.Titleanditem.Linkis crucial.item.TitleIt carries the semantics of categories and readability for users, which is a direct expression of the logical structure of the website content; anditem.LinkThis provides the unique access path to the category and is the core of the website structure and navigation function.Master their output methods and combination, and it will help you easily create a highly efficient website with clear structure, easy navigation, and search engine friendly.
Common Questions (FAQ)
Except
item.Titleanditem.Link,categoryListWhat information can be obtained in the loop?Besides the title and link,itemthe object also provides rich classification information, such asitem.Id(Category ID),item.Description(Classification description),item.Logo(Classification thumbnail large image),item.Thumb(Category thumbnail),item.HasChildren(Whether it includes subcategories) etc. You can output this information in a loop as needed,{{ item.属性名 }}in order to present the category content more finely.}If I want to customize the display format of category URLs, for example, to
/category/1.htmlchange it to/news/company-news.html, how should I operate?AnQiCMS provides powerful pseudo-static rule management functionality.You can set it in the "Function Management" -> "URL Rewrite Rule" in the background.{catname}or{filename}), AnQiCMS will automatically generate URLs that comply with your settings according to your configurationitem.Link[en] No need to modify the template code. This greatly enhances the website's SEO friendliness.If
item.Title[en] It displays as empty, oritem.Link[en] Cannot jump correctly, how should I troubleshoot the problem?Ifitem.TitleThe category name for this category is not filled in on the AnQiCMS backend. Please check first.item.LinkUnable to navigate correctly, possible reasons include: the background category has not been published or is disabled; the static rule configuration is incorrect or the server has not been properly activated (for example, if the Nginx or Apache configuration has not been refreshed); or incategoryListtagsmoduleIdorparentIdParameter settings are incorrect, resulting in the acquisition of incorrect data. It is recommended to investigate step by step from the three aspects of backend data checking, frontend template parameters, and server environment configuration.