How to implement nested display of multi-level categories in AnQiCMS navigation menu?

Calendar 👁️ 54

In website construction, a clear and easy-to-use navigation menu is crucial for improving user experience and the overall structure of the website.AnQiCMS (AnQiCMS) provides flexible settings for managing the navigation menu, allowing users to easily implement nested hierarchical classification displays, thereby better organizing website content and guiding visitors to explore.

To implement hierarchical navigation with nested categories, we mainly complete it through the "Navigation Settings" function in the AnQi CMS backend.This feature is located in the "Background Settings" area, it can not only manage the top navigation of the website, but also create various custom navigation as needed, such as footer navigation or sidebar navigation.

Configure navigation menu: Backend operation guide

First, enter the Anqi CMS backend, find the 'backend settings' under the 'navigation settings'.Here, you will see a 'Navigation Category Management' area.If your website needs multiple independent navigation areas (such as a main navigation, a footer link navigation), you can add different navigation categories here.The system defaults to have a "Default Navigation" category, which we can use directly or create a new one.

Next is the setting of specific navigation links. In the 'Navigation Link Settings' section, each navigation item is an independent link. The key here is the 'Parent Navigation' option.

  1. Create a first-level navigation:When you create a new navigation link, if you want it to be a main menu item (i.e., a top-level menu), just set the 'Parent Navigation' to 'Top-Level Navigation'.You can specify information such as "Display Name", "Link Type", etc.
  2. Create a second-level navigation (nested):The Anqi CMS supports nested navigation up to two levels. To create a second-level menu item, you need to select a first-level navigation item you just created in the 'Parent Navigation' option.This new link will be nested under the first-level navigation and become its submenu.For example, if you have a top-level navigation named 'Product Center', you can set 'Product Category A' and 'Product Category B' as sub-navigations under 'Product Center'.

When setting the link type, Anq CMS provides three commonly used options:

  • Built-in links:Pages suitable for linking to specific feature pages of a website, such as the homepage, article model homepage, product model homepage, etc.
  • Category page links:This is the key to combining website content with navigation. You can directly select the 'Document Category' or 'Single Page' that you have created as a navigation link.For example, if you create a "News" category in content management, you can select this category in the navigation settings to link the navigation item directly to the news list page.
  • External links:Allows you to flexibly add any internal or external URL addresses.

Additionally, the "Display Order" field allows you to control the arrangement order of navigation items at the same level, with smaller numbers typically appearing earlier, making it easier for you to adjust the display order of the menu based on the website layout.

Display multi-level navigation on the website front-end: template calling method

After completing the background configuration, we need to display these multi-level navigation menus on the website page.This needs to be called through a specific tag in the template file. Anqi CMS adopts a syntax similar to the Django template engine, using double curly braces for variables{{变量}}Logical control tags are used with single curly braces and percentage signs{% 标签 %}.

You will use it to display the navigation menunavListLabel. This label can retrieve the navigation list you configure in the background and supports multi-level nested output.

This is a typicalnavListLabel usage example, it can display two-level navigation:

{% navList navs %}
<ul>
    {%- for item in navs %} {# 遍历一级导航项 #}
        <li class="{% if item.IsCurrent %}active{% endif %}">
            <a href="{{ item.Link }}">{{item.Title}}</a>
            {%- if item.NavList %} {# 如果存在子导航列表 #}
            <dl>
                {%- for inner in item.NavList %} {# 遍历二级导航项 #}
                    <dd class="{% if inner.IsCurrent %}active{% endif %}">
                        <a href="{{ inner.Link }}">{{inner.Title}}</a>
                    </dd>
                {% endfor %}
            </dl>
            {% endif %}
        </li>
    {% endfor %}
</ul>
{% endnavList %}

In this code block:

  • {% navList navs %}Called the navigation list and assigned the result tonavsa variable. If you have created multiple navigation categories in the background, you canwith typeId=Xspecify the category to be called.
  • The outermost{% for item in navs %}Loop to traverse all first-level navigation items. Eachitemrepresents a navigation link, itsTitleIs the display name,Linkis the link address.
  • {% if item.NavList %}Determine if the current first-level navigation item contains a submenu. If it contains,item.NavListIt will be an array containing all the second-level navigation items.
  • Inner layers.{% for inner in item.NavList %}The loop is used to iterate over the second-level navigation items.innerIt also hasTitleandLinksuch properties.
  • {% if item.IsCurrent %}active{% endif %}This judgment can be used to add the corresponding navigation item for the current page.activeThe class facilitates highlighting through CSS styles, enhancing user experience.

By using such a template structure, you can clearly present the multi-level navigation menu configured in the background on the website page. If the navigation items link to specific category pages (such as article categories, product categories), you can even further call the secondary navigation items belowarchiveListLabel, display part of the articles or products under this category, forming a more rich content display effect.

The navigation settings of AnQi CMS are designed to provide an intuitive and powerful menu management solution.By reasonably planning the navigation structure of the backend and appropriately calling it in the template, your website will have a multi-level navigation system that is both beautiful and efficient, effectively improving the browsing experience of users.

Frequently Asked Questions (FAQ)

1. How many levels of nesting does the Anqi CMS navigation menu support?The navigation menu of Anqi CMS currently supports up to two levels of nesting. This means you can set up a primary menu and its sub-menus below.

2. How do I add the website's 'Article Category' or 'Product Category' to the navigation menu?Create or edit navigation links in the background "Navigation Settings", select "Link Type" as "Category Page Link", and then select the "Document Category" or "Single Page" you want to link from the pop-up list.

3. Why did I set a second-level menu, but the front-end page only displays the first-level menu?This is usually due to the template file not being properly written or configured to display the secondary menu. Please check if you have used something similar in your template code.{% if item.NavList %}This logic is used to judge and loop output the submenu items, ensure that the template can recognize and renderitem.NavListThe content is. Also, make sure the background "parent navigation" settings are correct, ensuring that the secondary menu is indeed associated with the primary menu.

Related articles

How to display the subcategory list under the AnQiCMS category page?

In AnQiCMS, you can easily display the subcategory list under the category page with flexible template tags.This is crucial for building a clear website structure, improving user navigation experience, and optimizing search engine crawling efficiency.AnQiCMS powerful template system and its Django-style tag syntax make the display of such dynamic content intuitive and efficient.To implement displaying the subcategory list under the category page, the following steps are mainly involved:

2025-11-08

How does AnQiCMS display the list of all top-level categories?

In website construction and content operation, clear classification navigation is the foundation of user experience, as well as the core of content organization.For users using AnQiCMS, how to efficiently display the list of all top-level categories of the website is the first step in building the website structure.AnQiCMS with its flexible template engine and rich built-in tags makes this task exceptionally simple and intuitive.

2025-11-08

How to filter and display a specific list of articles based on recommended properties (Flag) in AnQiCMS?

An QiCMS provides operators with rich tools for organizing and displaying website content with its flexible and efficient content management capabilities.Among the "recommended attributes" (Flag) is a very practical feature that allows you to easily categorize and mark articles, thereby enabling accurate content filtering and dynamic display on the website front end.This article will introduce in detail how to use these recommended attributes in AnQiCMS to filter and display the specific article list you want.### Deep Understanding of AnQiCMS Recommendation Attributes (Flag) AnQiCMS Recommendation Attributes

2025-11-08

How to nested display the list of articles under the category page in AnQiCMS?

In website operation, the content classification page carries the important responsibility of organizing information and guiding users to browse.A well-designed and content-rich category page can not only improve user experience but also optimize search engine crawling efficiency.For users of AnQiCMS, nesting the list of articles under the category page is a very basic and commonly used feature.This article will introduce you in detail on how to use the powerful template tags of Anqi CMS to easily achieve this goal.Understanding the Classification Page and Content Model Before we begin

2025-11-08

How to obtain and display the detailed description information of AnQiCMS categories?

In website operation, clear and detailed classification descriptions are crucial for user experience and search engine optimization.AnQiCMS as a powerful content management system provides a flexible way to manage and display these category information.This article will delve into how to retrieve and effectively display detailed category descriptions on the frontend page in AnQiCMS.

2025-11-08

How to call and display the Banner image of the AnQiCMS category page

In website operation, the category page is not only the display of content classification, but also a key entry for users to explore the website and gain a deeper understanding of products or services.A well-designed category banner image that can effectively enhance the visual appeal of the page, strengthen the brand image, and guide users to the next step of operation.AnQiCMS as an efficient content management system, provides a flexible way to manage and call these banner images. We will delve into how to set up a Banner image for category pages in AnQiCMS and display it on the website frontend.###

2025-11-08

How to create a custom template for AnQiCMS website to achieve personalized display?

AnQiCMS with its flexible and efficient features provides a wide space for personalized display of website content.If you want your website to have a unique look and function, creating a custom template is undoubtedly the way.By deeply customizing the template, you can fully control every detail of the website, from brand image to user experience, achieving high levels of personalization and standing out among many websites.This article will guide you to understand how to create and apply custom templates in AnQiCMS, helping you to turn your design ideas into reality and realize the personalized display of the website

2025-11-08

What template types does AnQiCMS support, and how do you choose the most suitable display mode for the website (adaptive, code adaptation, PC + mobile end)?

AnQiCMS as an efficient and customizable content management system provides a variety of flexible modes for displaying website content to meet the diverse needs of different users.Understanding these template types and their applicable scenarios is crucial for building a website with a good user experience, easy management, and search engine optimization.AnQiCMS provides three main template types for users to meet the display needs of different websites.They are adaptive templates, code adaptation templates, and independent PC + mobile site templates.Each pattern has its unique characteristics and applicable scenarios

2025-11-08