How to build a multi-level category navigation in Anqi CMS template and judge whether each category has subcategories?

Calendar 81

In today's increasingly rich website content, a clear and efficient navigation system is crucial for enhancing user experience and search engine optimization (SEO).Especially for websites with a large amount of content or multiple product categories, multi-level category navigation can help users quickly find the information they need while also displaying the structural hierarchy of the website to search engines.AnQi CMS with its flexible and powerful template engine makes it simple and intuitive to build such navigation.This article will deeply explore how to cleverly construct multi-level category navigation in the Anqi CMS template, and intelligently judge whether each category contains subcategories, making your website navigation more dynamic and intelligent.

Understand the template basics of Anqi CMS

The AnQi CMS template system adopts a syntax similar to the Django template engine, which is very friendly to developers and easy to learn.It allows us to dynamically display data through specific tags and variables.When building category navigation, it is mainly usedcategoryListLabel, as wellifandforSuch logic control tags. These tags together constitute the foundation for us to implement complex navigation logic.

The core of building multi-level classification navigation:categoryListTag

categoryListThe tag is designed specifically for obtaining the category list in AnQi CMS, it can filter out different models and categories at different levels according to our needs.

  • Specify the content model (moduleId)Your website may contain articles, products, and various content models. Categories under each model are independent. ThroughmoduleIdThe parameter allows you to specify precisely which category of content model you want to retrieve. For example,moduleId="1"typically represents an article model,moduleId="2"may represent a product model.
  • Specify the parent category (parentId)This is the key to implementing multi-level navigation.
    • WhenparentId="0"Then, you will retrieve all top-level categories under the specified content model.
    • WhenparentIdSet the ID of a specific category, and it will retrieve all direct subcategories under that category.
    • If you want to get the sibling categories of a certain category (i.e., all child categories that belong to the same parent category), you can do so by using the parent category ID if it is known.parentIdtransmittedcategoryList.

Does the category have subcategories:item.HasChildren

In the loopcategoryListWhen the category data obtained by the tag is, each category (usually named in the loop) has a very useful attribute:itemEach category (usually in parentheses) has a very useful attribute:HasChildren. This is a boolean value, if the current category has subcategories,HasChildrenThe value istrue; otherwise,false.Using this property, we can flexibly control the display logic of navigation in the template, for example, only showing the container of the secondary menu under items with subcategories, thus avoiding unnecessary empty menus.

Actual operation: build multi-level category navigation

Now, let's take a specific example to show how to build a two-level or more hierarchical classification navigation in the template.

Assuming we want to build a navigation menu that displays article categories, including primary categories and their subcategories:

`twig {# Get all top-level categories under the article model (assuming moduleId is 1) #} {% categoryList categories with moduleId=“1” parentId=“0” %}

Related articles

How to retrieve and display custom document parameters for a specific named using the `archiveParams` tag?

In AnQi CMS, content management is not limited to preset fields such as titles, content, etc., but can also be enriched and expanded by custom parameters.When you set unique custom fields for articles, products, or other content models, how to accurately obtain and display these specific parameter names in the front-end template is a common requirement in template creation.This article will deeply explore how to flexibly obtain and display the custom parameters of the `archiveParams` tag.### Custom parameter setting

2025-11-08

How to retrieve all custom parameters of a document in an Anqi CMS template and display them in a fixed order?

In website content management, we often need to define unique attributes for different types of information to meet the diverse display needs of the website.The AnQi CMS provides powerful custom parameter functionality, allowing you to flexibly add additional information to documents (articles, products, etc.)When you want to obtain these custom parameters in the website front-end template and display them in the fixed order set in the background, the built-in template tags of Anqi CMS can well help you achieve this.

2025-11-08

How to combine the `archiveList` tag with query parameters in the URL to implement dynamic search and filtering?

Build an interactive and easy-to-navigate website on Anqi CMS, with dynamic search and filtering functions being indispensable.`archiveList` tag as the core tool for content output, cleverly combines URL query parameters, and can help us implement a powerful content discovery mechanism, allowing users to easily locate the information they are interested in. ### The core function of the `archiveList` tag The `archiveList` tag is used in AnQi CMS to retrieve and display document lists.

2025-11-08

How to loop through a document list in an Anqi CMS template and output custom parameters for each document?

AnQiCMS provides powerful template customization capabilities, allowing us to flexibly display various content according to the actual needs of the website.When we not only need to loop through the document list but also want to output unique custom parameters for each document, the template tags of AnQiCMS can well help us achieve this.This is particularly important for a content model that has diversified attributes for displaying product details, real estate information, job openings, etc.

2025-11-08

How to display documents under the current category using the `categoryList` tag without including documents from subcategories?

When building a website with Anq CMS, we often encounter such a need: on a category page, we want to display only the documents that belong to the current category, and not mix in the document content of its subcategories.This is particularly important in scenarios where the content structure is clear and avoids redundancy.Today, let's discuss in detail how to accurately achieve this goal through the template tags of Anqi CMS. ### Understanding AnQiCMS Classification and Document Relationship AnQiCMS has always fully considered the flexibility of content hierarchy from the beginning of its design.A category can have subcategories

2025-11-08

How to use the `navList` tag to create a navigation bar with submenus in the Anqi CMS template?

In AnQi CMS template development, building a functional and user-friendly navigation bar is one of the core tasks of website frontend development.Especially when navigation needs to include multi-level sub-menus, the `navList` tag provided by Anqi CMS can help us efficiently meet this requirement.Understanding the core role of the `navList` tag The `navList` tag is a tool specifically used in the Anqi CMS template to retrieve website navigation data and display it on the page.

2025-11-08

How to determine if the current navigation item is the current page in the `navList` loop?

In website operation, a clear navigation structure is crucial for improving user experience.A good navigation not only helps visitors quickly find the information they need, but also guides users through visual cues (such as highlighting the current page) so that they always know where they are.In AnQi CMS, implementing this feature is quite intuitive and efficient, which is due to its powerful template tag system.

2025-11-08

How to dynamically generate a custom field comment form with `guestbook` tag and adapt to different input types?

Managing website comments in Anqi CMS is a common requirement in daily operations, especially when we need to collect specific information, a flexible and customizable comment form becomes particularly important.Aqie CMS fully considers this requirement and provides a powerful `guestbook` tag, allowing us to easily dynamically generate a feedback form with custom fields and adapt to various input types.The power of the `guestbook` form label The core lies in the `guestbook` tag

2025-11-08