What do `categoryList` loop's `item.Title` and `item.Link` represent, and how to output?

Calendar 👁️ 71

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)

  1. exceptitem.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.

  2. 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 friendliness

  3. Ifitem.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); or categoryListin 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.

Related articles

How do I correctly use the `all=true` parameter of `categoryList` to display all categories in the sidebar?

In Anqi CMS, efficiently managing and displaying website content is the key to operational success.The sidebar acts as an important navigation area for websites, often needing to display clear categories to guide users quickly to the information they need.When you want to display all categories in the sidebar and are puzzled by the `all=true` parameter of the `categoryList` tag, this is exactly the topic we will delve into today.In AnQi CMS, categories are the framework for organizing website content.

2025-11-06

Does the `categoryList` tag support limiting the number of categories returned? How to set the `limit` parameter?

As an experienced website operations expert, I know how important it is to have precise control over content display when building and optimizing a website.AnQiCMS as an efficient and flexible content management system, its powerful template tag system provides us with abundant operating space.Today, let's delve into the function of the `categoryList` tag in limiting the number of returned categories, as well as how to巧妙ly use the `limit` parameter.

2025-11-06

How to get the list of all direct subcategories of the current page category?

As an experienced website operations expert, I am well aware that how to efficiently organize and display the classification structure is crucial when managing a content-rich website.AnQiCMS (AnQiCMS) with its powerful template tag system provides us with great flexibility, making it easy to achieve various complex classification display needs.Today, let's delve into a common and practical scenario: how to obtain and display the list of all direct subcategories under the current page category.

2025-11-06

What is the specific function and application scenario when the `parentId` parameter of `categoryList` is set to "0"?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system, whose powerful template tag system is the key to content operators achieving personalized display.Among many practical tags, the `categoryList` tag is undoubtedly an important tool for building the framework of a website.Today, let's delve into the `categoryList` tag and its seemingly simple yet extraordinary parameter `parentId="0"`. What specific role and application scenarios does it have?

2025-11-06

How can you determine if a category has a subcategory? How can the `item.HasChildren` field be applied to conditional judgments?

As an experienced website operations expert, I deeply understand the importance of efficiently using template tags in the daily application and content strategy formulation of AnQiCMS (AnQiCMS).Today, let's delve deeply into a very practical topic in website structure construction: how to determine whether a category (Category) contains subcategories, and how to cleverly use the `item.HasChildren` field in templates to achieve intelligent content display.

2025-11-06

Can the `categoryList` tag display the number of documents under each category? How can `item.ArchiveCount` be retrieved and displayed?

As an experienced website operation expert, I know that how to efficiently and intuitively display content data in a content management system is the key to improving user experience and content operation efficiency.AnQiCMS (AnQiCMS) offers us great flexibility with its simple and efficient architecture.Today, let's delve deeply into a question that both operators and template developers are very concerned about: Can the `categoryList` tag display the number of documents under each category?How to get and display `item.ArchiveCount`?” --- ##

2025-11-06

How to display a category thumbnail (`item.Thumb`) or Banner image (`item.Logo`) next to the category list?

As an experienced website operation expert, I am well aware of the importance of the visual presentation of website content in terms of user experience and information delivery.In a powerful and flexible system like AnQiCMS, we have multiple ways to achieve fine-grained content control, especially in key navigation areas like category lists. How to effectively display category thumbnails or Banner images is an important aspect to enhance the professionalism and attractiveness of a website.Today, let us delve into how to cleverly integrate these visual elements into the category list in Anqi CMS.--- ###

2025-11-06

What is the actual use of the `item.Spacer` field in multi-level category display, and how to beautify the prefix?

As an experienced website operations expert, I know that every seemingly minor feature in a content management system may play a key role in user experience and content presentation.Today, let's delve deeply into a frequently overlooked but indispensable field in AnQiCMS, which is essential for building a clear and hierarchical content structure - `item.Spacer`.

2025-11-06