How to use AnQiCMS navigation list tags to display two-level or multi-level menu structures?

Calendar 👁️ 86

The operation of a website is like steering a ship, and a clear navigation system is like a compass guiding the way.In the world of content management, a highly efficient and flexible navigation menu can greatly enhance user experience, allowing visitors to navigate your website effortlessly, and is an important cornerstone for optimizing website structure and improving search engine friendliness.AnQiCMS (AnQiCMS) fully understands its path, providing users with a powerful and intuitive navigation list tag, making it easy to build a multi-level menu structure.

Today, let's delve into how to skillfully use in AnQiCMSnavListTags, easily create a two-level or multi-level menu structure that is both beautiful and practical.

AnQiCMS navigation system: lays the foundation for backend configuration

In AnQiCMS, the first step in building a multi-level menu is naturally to make detailed configurations in the background.The system provides the "website navigation settings" feature, allowing you to flexibly define the navigation links of the website according to your actual needs.

First, you will notice the "Navigation Category Management". This allows you to create different navigation areas, such as common "Top Navigation", "Footer Navigation", or "Sidebar Navigation".This classification management method is very practical, you can customize exclusive navigation content for different page areas without interference.

Next is the "Navigation Link Settings", this is where you actually build the menu hierarchy.When adding or editing navigation links, you need to set the "Display Name", "Link Type", and the most important "Parent Navigation".“Link type” is very rich, you can choose “Built-in link” (such as homepage, article model homepage), “Category page link” (related to specific article categories or single pages), or “External link” (pointing to any URL within or outside the site).

By reasonably selecting the 'parent navigation', you can easily build a two-level menu structure.For example, a first-level menu named "Product Center" can include second-level menus such as "Electronic Products", "Home Goods", and so on.Just set the 'Parent Navigation' of 'Electronics' to 'Product Center'.The backend design of AnQiCMS is very intuitive, usually you can directly configure two-level menus in this way, meeting the needs of the vast majority of corporate websites.

RevelationnavListTags: magic of front-end templates

After the background configuration is in place, the front-end template is the key to beautifully presenting the structured navigation data. AnQiCMS provides powerful features for this.navList.

navListThe tag is specifically used to retrieve and display the page navigation list, its basic usage is concise and clear. You would usually start your navigation code snippet like this:

{% navList navs %}
    {# 导航内容将在这里循环输出 #}
{% endnavList %}

Here, navsWe define the variable name for the navigation list data, you can name it according to your habits.navListThe tag also supports some parameters, such astypeIdIt allows you to specify which "navigation category" link to call. For example, if you create one in the background,typeIdyou can navigate to the "footer navigation" for 2 in the template.{% navList navs with typeId=2 %}Call it. Another parametersiteIdIt is used for multi-site management scenarios, allowing you to call data from specific sites.

InnavsIn this variable, each navigation item contains a series of available fields, such asTitle(Navigation title),Link(navigation link),IsCurrent(Determine whether it is a link on the current page, often used to highlight the active menu item) and a very critical field -NavList.

NavListThe presence of a field is the key to implementing multi-level menus. If a navigation item contains a sub-navigation, thenNavListIt will become an array containing these sub-navigation items. This allows us to perform nested loops in the template, thus displaying the menu structure layer by layer.

Implement a two-level menu structure

Now, let's go through a real code example to see how to make use ofnavListtags to elegantly display a two-level menu on the front end:

<nav class="main-navigation">
    <ul class="primary-menu">
        {% navList navs with typeId=1 %} {# 假设typeId=1是顶部导航 #}
            {% for item in navs %}
                <li class="menu-item {% if item.IsCurrent %}active{% endif %} {% if item.NavList %}has-submenu{% endif %}">
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                    {% if item.NavList %} {# 检查是否有子导航 #}
                        <ul class="sub-menu">
                            {% for inner in item.NavList %}
                                <li class="menu-item {% if inner.IsCurrent %}active{% endif %}">
                                    <a href="{{ inner.Link }}">{{ inner.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

This code clearly demonstrates the construction logic of a two-level menu: First, the externalfor item in navsloop through all the first-level navigation items. Inside each first-level navigation item, we use{% if item.NavList %}Determine if it contains child navigation. If child navigation exists, use another nested loop.{% for inner in item.NavList %}To iterate and display all second-level navigation items.item.IsCurrentandinner.IsCurrentIt is used to add to the currently active menu item.activeclass, easy to highlight through CSS.

Advanced: Explore the display strategies of three-level or more menu.

The native 'Navigation Link Settings' of AnQiCMS supports the configuration of two-level menus directly, but by cleverly combining other content tags, we can fully realize the dynamic display of three-level or even more menu levels in the front-end template, thereby building a richer and more flexible navigation system.

The core idea is: to bind a certain item of the second-level menu with its associated 'content category' or 'content list', and then dynamically pull more hierarchical data through these content tags on the front-end.

For example, a typical application scenario is: First-level menu -> Second-level category menu -> The article list under this category (as the third-level menu). Or: First-level menu -> Second-level category menu -> The list of subcategories under this category (as a third-level menu).

Let us refertag-/anqiapi-other/165.htmlto the example to see how to implement such an advanced menu structure:

Scenario one: Display related product documents under the second-level category (as the third level)

Assuming your navigation backend is configured with 'Product Center' as a top-level menu, under which there is a 'Electronics' as a sub-menu, and this 'Electronics' sub-menu is associated with a product category ID.We hope that when clicking on 'Electronics', the popular products under this category will be displayed in the dropdown menu.

<ul class="main-menu">
    {% navList navList with typeId=1 %}
        {% for item in navList %}
        <li>
            <a href="{{ item.Link }}">{{ item.Title }}</a>
            {% if item.NavList %} {# 一级菜单的子导航,即二级菜单 #}
            <ul class="sub-menu">
                {% for inner in item.NavList %}
                <li>
                    <a href="{{ inner.Link }}">{{ inner.Title }}</a>
                    {% if inner.PageId > 0 %} {# 检查二级菜单是否关联了某个分类ID #}
                        {% archiveList products with type="list" categoryId=inner.PageId limit="8" %} {# 假设inner.PageId是产品分类ID,获取该分类下8个产品 #}
                            {% if products %} {# 如果有产品,则显示为三级菜单 #}
                            <ul class="tertiary-menu">
                                {% for product_item in products %}
                                <li><a href="{{ product_item.Link }}">{{ product_item.Title }}</a></li>
                                {% endfor %}
                            </ul>
                            {% endif %}
                        {% endarchiveList %}
                    {% endif %}
                </li>
                {% endfor %}
            </ul>
            {% endif %}
        </li>
        {% endfor %}
    {% endnavList %}
</ul>

In this example,inner.PageIdIt represents the category ID associated with the secondary navigation link. We usearchiveListthe tag, tocategoryId=inner.PageIdas a condition to dynamically pull the product list under the category and display it as the third-level menu.

Scenario two: Display subcategories under the second-level category (as the third level)

If your requirement is to display a deeper level of categorization, for example, under the second-level menu of "Electronics", displaying more specific subcategories such as "Smartphones", "Laptops", and so on.

`twig

Related articles

What are the advantages of the "Flexible Content Model" project of AnQi CMS, and how is customization manifested on the front end through tags like `moduleDetail`??

## AnQi CMS: How to create a versatile front-end experience through `moduleDetail` and other tags As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its flexibility and adaptability.In today's rapidly changing digital marketing environment, a rigid, difficult-to-customize system undoubtedly becomes a fetter to corporate development.AnQiCMS (AnQiCMS) delivered a satisfactory answer to this challenge with its high-performance architecture based on the Go language

2025-11-07

`moduleDetail` tag fetches the model introduction (`Description`) does it support HTML content?How to safely render in the template?

As an experienced website operation expert, I fully understand the specific problems you may encounter in AnQiCMS template development and content operation.Flexible content display is the core advantage of CMS, but the content security and correct rendering that come with it also need our careful consideration.Today, let's delve deeply into whether the `moduleDetail` tag supports HTML content in the model description (`Description`) and how to safely render it in the template.### Unveiling AnQiCMS

2025-11-07

How to dynamically display all custom fields under the current content model in the template, including their `parameter name` and `field call`?

Among the powerful feature matrix of Anqi CMS, the content model and custom fields are undoubtedly one of its core highlights.It provides the website with great flexibility, allowing operators to build various types of content structures such as articles, products, services, and cases according to actual business needs.However, for operators unfamiliar with template development, it is often a challenge to dynamically and elegantly display these diverse custom fields on the website front-end, especially when it comes to showing both their 'parameter name' and 'actual value' at the same time.

2025-11-07

Can I configure different publishing processes or review mechanisms for different content models? Will this affect the use of the `moduleDetail` tag?

As an experienced website operations expert, I am more than happy to delve deeply into the powerful capabilities of Anqi CMS in content model configuration and publishing process.AnQi CMS, with its efficient architecture in Go language and excellent customizability, indeed provides us with great flexibility in content operations, especially when dealing with different types of content, it can provide differentiated management strategies.Let's dive straight into the core issue: **Can AnQi CMS configure different publishing processes or review mechanisms for different content models?Does this affect the usage of the `moduleDetail` tag?

2025-11-07

How to determine the currently active (active) navigation item in the AnQiCMS navigation list?

As an experienced website operation expert, I fully understand the importance of navigation menus for user experience and website structure.An active navigation item that can clearly indicate the current position, not only can it improve the user's browsing efficiency, but also provide positive visual feedback.In such an efficient and user-friendly content management system as AnQiCMS (安企CMS), the realization of this feature is equally concise and powerful.Today, let's delve into how to cleverly judge and mark the currently active navigation item in the AnQiCMS navigation list, making your website navigation smarter and smoother

2025-11-07

How to create a new navigation category in the AnQiCMS backend, such as footer navigation or sidebar navigation?

## Unlock a new dimension of website layout: easily create custom navigation categories in AnQi CMS background As an experienced website operations expert, I am well aware of the importance of a flexible and efficient content management system for website success.AnQiCMS, with its high-performance architecture based on the Go language, modular design, and SEO-friendly features, has become the first choice for many small and medium-sized enterprises and content operation teams.Its strong performance in content management, not only reflected in the publication and management of core content such as articles and products, but also in its highly customizable navigation system

2025-11-07

How to specify different navigation categories with the `typeId` parameter of AnQiCMS navigation tags?

As an experienced website operations expert, I know that a flexible and efficient navigation system is crucial for website user experience and Search Engine Optimization (SEO).AnQiCMS does an excellent job in this aspect, it provides great convenience for the customization of website navigation through its powerful template tag system, especially with the `navList` tag配合`typeId` parameter.Today, let's delve deep into the mysteries of this `typeId` parameter and how to cleverly use it to manage different types of navigation categories.

2025-11-07

How to get the link address and display name of the navigation item in the AnQiCMS template?

As an experienced website operations expert, I am well aware of the importance of an efficient and flexible CMS system for content operations.AnQiCMS with its powerful performance in Go language and the ease of use of the Django template engine indeed provides us with great convenience.Today, let's delve deeply into an important topic in website template development: how to accurately obtain the link address and display name of navigation items in AnQiCMS templates?

2025-11-07