As a seasoned 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 is an enterprise-level content management system based on the Go language, and its simple and efficient template engine is very appealing to me.Today, let's delve deeply into AnQiCMS template development,categoryListin the loopitem.Titleanditem.LinkWhat does it represent, and how should we elegantly present it in the template.
RevelationcategoryListThe core element in the loop:item.Titlewithitem.Link
In the world of AnQiCMS templates,categoryListTags are the core tools for obtaining and displaying website classification information. Whether it is to build the main navigation menu, the sidebar classification list, or the category entry on the homepage, categoryListThey are essential tools for us. When you use this tag to traverse classified data, it will return a collection containing multiple "items".These "items" are each specific categories, anditem.Titleanditem.LinkThese are the most basic and most important properties of these categories.
item.Title: The face of the category
We can combineitem.TitleImagine it as the 'face of each category'. It represents the current loop inThe display name of the category. This name is the most intuitive text information facing the user, such as "Company News", "Product Center", "Contact Us", etc.It is usually used for navigation bar text, category list titles, or any place where the category name needs to be displayed to the visitor.
In AnQiCMS,item.TitleThe value directly comes from the 'Category Name' you set in the backend.It is not only the basis for user identification classification, but also one of the key texts for search engines to understand the content of the page.Therefore, writing clear and descriptive category titles is crucial for improving user experience and SEO performance.
Output in the templateitem.TitleJust place it in double curly braces{{ }}in it. For example:
{{ item.Title }}
This will directly display the name of the current loop category on the web page.
item.Link: The bridge to content
If we sayitem.Titleis the name of the category, thenitem.Linkis the only path to this category pageunique 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 displaying 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 SEO-optimized friendly URL. A well-structured, semantic clearitem.LinkThe overall architecture of the website, user navigation experience, and search engine crawling all play a decisive role.
Output in the templateitem.LinkThe most common application scenario is as HTML<a>label'shrefAttribute value, make the category 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 basic 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.
This is a typicalcategoryListLoop combinationitem.Titleanditem.LinkAn example, demonstrating how to create a basic category 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 get all top-level categories under the model with ID 1 (usually the article model), and assign these category data toparentId="0")categoriesVariable.{% for item in categories %}We continue to traversecategoriesThis collection, each loop will assign a category of data toitemVariable.<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>In the loop body, we willitem.Linkas<a>label'shrefProperty,item.TitleAs link display text. In this way, each category is rendered as a clickable navigation item, which can be clicked to jump to the corresponding category page.
In this way, AnQiCMS enables template developers to build complex website structures with great flexibility and efficiency, while ensuring accessibility and SEO-friendliness.
Summary
UnderstandingcategoryListLoopitem.Titleanditem.Linkis crucial in the template development of AnQiCMS.item.TitleIt carries the semantics of classification and readability for users, and is a direct expression of the logical content of the website; anditem.LinkIt provides the only way to access the category, which is the core of the website structure and navigation function.Master their output methods and combination, and you will easily create a website with clear structure, easy navigation, and search engine friendly efficiency.
Frequently Asked Questions (FAQ)
except
item.Titleanditem.Link,categoryListWhat information can still be obtained in the loop?Besides titles and links,itemThe object also provides rich classification information, such asitem.Id(Category ID),item.Description(Category Description),item.Logo(Category thumbnail large image),item.Thumb(Category Thumbnail),item.HasChildren(Whether it includes subcategories) and so on. You can do the same as needed, through{{ item.属性名 }}The way to output these information in a loop, in order to display the classification content more finely.If I want to customize the display format of the classification URL, for example, how should I operate?
/category/1.htmlto/news/company-news.htmlWhat should I do?AnQiCMS provides powerful pseudo-static rule management functions.You can set up the "Feature Management" -> "URL Rewrite Rule" in the background.By configuring a custom pattern, you can change the category URL pattern from the default numeric ID pattern to a more semantic naming pattern (such as{catname}or{filename}),AnQiCMS will automatically generate rules-based content according to your settingsitem.Link. No need to modify the template code. This greatly improves the website's SEO friendlinessIf
item.Titleor it will be displayed as emptyitem.LinkUnable to navigate correctly, how should I troubleshoot the problem?Ifitem.TitleEmpty display, first check if the "Category Name" for this category in AnQiCMS backend has been filled out. Ifitem.LinkUnable to navigate correctly, possible reasons include: categories not published or disabled in the background; incorrect configuration of pseudo-static rules or the server not functioning properly (e.g., Nginx or Apache configuration not refreshed); orcategoryListin the tagmoduleIdorparentIdIncorrect parameter settings have led to the retrieval of incorrect data. It is recommended to check the background data, front-end template parameters, and server environment configuration in a step-by-step manner.