How to build a multi-level dropdown menu and display the navigation list tags in AnQiCMS?

Calendar 👁️ 66

The website navigation serves as the core entry point for users to explore the website content, and its structural design directly affects user experience and the efficiency of information acquisition.Especially multi-level drop-down menus can effectively organize a large amount of information, making the website structure clearer and more hierarchical.In AnQi CMS, building and displaying such a multi-level navigation system is both flexible and intuitive.

To successfully build a multi-level dropdown menu, we need to combine the backend navigation configuration with the frontend template tag calls.

The first step is to understand the data structure of the Anqi CMS navigation list and the background configuration

In Anqi CMS, to build a multi-level dropdown menu, you first need to start with the navigation settings in the background. Enter the background's后台设置-u003e网站导航设置Page, you will see导航类别管理and导航链接设置Two core areas.

1. Navigation category management:The system provides a default "default navigation" category, and you can create new navigation groups according to your actual needs, such as "main navigation", "footer navigation", or "sidebar navigation", by customizing the navigation categories.The benefit of doing this is that it can be managed and called independently for the navigation of different areas of the website.

2. Navigation link settings:This is the place to create specific navigation menu items. Each navigation link carries specific information, such as the displayed name, link address, etc.

  • Display Name and Subtitle Name/Navigation Description:These fields allow you to set friendly display text for navigation items, and even add auxiliary subtitles or descriptions to provide more rich information.
  • Link Type:The AnQi CMS supports various link types, including links to core pages within the site内置链接(such as the homepage, model homepage), and links to specific pages分类页面链接(Article category, product category, or single page), and fully customizable外部链接. This greatly enhances the flexibility of navigation.
  • Parent navigation:This is the key to implementing a multi-level menu. When you need to create a second-level menu item, just上级导航Set it as the corresponding top-level menu. For example, if you create a top-level navigation named "Product Center", you can then create secondary navigations such as "Product A", "Product B", and so on, and set their上级导航Be specified as "Product Center".
  • Display order:By adjusting the display order number, you can control the arrangement position of navigation items at the same level, the smaller the number, the closer to the front.

It should be noted that AnQi CMS currently supports up to two-level navigation lists by default.This means you can create a first-level menu and its second-level sub-menus, but not support three or more nested levels.

Second step: Master the navigation list labelnavListUsage of

After the background navigation structure is configured, the next step is to use the template in the front-endnavListlabel to display it.navListThe tag is a powerful tool provided by Anqi CMS, used to retrieve and loop output the navigation data configured on the backend.

The basic usage method is as follows:

{% navList navs %}
    {# 循环输出一级导航项 #}
    {%- 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 %}
{% endnavList %}

In this code block:

  • {% navList navs %}Declared the navigation data obtained and assigned to a variable namednavs.
  • {%- for item in navs %}Used to iterate over all first-level navigation items.itemThe variable represents the current first-level navigation object.
    • item.Title: Displays the name of the navigation item.
    • item.Link: The link address of the navigation item.
    • item.IsCurrentA boolean value indicating whether the current navigation item is a link to the current page, commonly used to addactiveto highlight the class.
  • {%- if item.NavList %}Is the key to determine whether the current top-level navigation item contains a submenu. Ifitem.NavListIf present, it indicates the existence of secondary navigation.
  • {%- for inner in item.NavList %}Used to iterate over all secondary navigation items under the current primary navigation item.innerThe variable represents the current secondary navigation object, which also hasTitle/Link/IsCurrentsuch properties.

If you have created multiple navigation categories in the background, you cantypeIdspecify a parameter to call a specific navigation group, for example:{% navList navs with typeId=2 %}.

Third step: Practical cases and advanced applications

To better displaynavListLabel flexibility, the following provides several practical cases to help you build different forms of multi-level dropdown menus.

Case one: Build a simple two-level standard dropdown menu.

This menu is usually used at the top of the website, and the secondary menu under it will expand when the mouse hovers over the first-level menu.

<nav class="main-nav">
    <ul class="nav-list">
        {% navList navs with typeId=1 %} {# 假设typeId=1是主导航 #}
        {%- for item in navs %}
            <li class="nav-item {% if item.NavList %}has-dropdown{% endif %} {% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{item.Title}}</a>
                {%- if item.NavList %}
                <ul class="dropdown-menu">
                    {%- for inner in item.NavList %}
                        <li class="dropdown-item {% if inner.IsCurrent %}active{% endif %}">
                            <a href="{{ inner.Link }}">{{inner.Title}}</a>
                        </li>
                    {% endfor %}
                </ul>
                {% endif %}
            </li>
        {% endfor %}
        {% endnavList %}
    </ul>
</nav>

This structure needs to be combined with CSS to control the display/hide of the dropdown menu (for example, using:hover), and JavaScript to implement more complex interactive effects.

Case two: Displaying the document list under the category in the navigation dropdown menu

In certain scenarios, you may want the secondary menu to be more than just links, but to directly display the latest articles or products under a specific category. This can be achieved by integratingnavListinternallyarchiveListthe tag.

<nav class="main-nav">
    <ul class="nav-list">
        {% navList navs with typeId=1 %}
        {%- for item in navs %}
            <li class="nav-item {% if item.NavList %}has-dropdown{% endif %} {% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{item.Title}}</a>
                {%- if item.NavList %}
                <ul class="dropdown-menu">
                    {%- for inner in item.NavList %}
                        <li class="dropdown-item">
                            <a href="{{ inner.Link }}">{{inner.Title}}</a>
                            {# 如果二级导航是分类页面,且存在对应的PageId,则可以调用该分类下的文档 #}
                            {% if inner.PageId > 0 %}
                                {% archiveList products with type="list" categoryId=inner.PageId limit="5" %}
                                {% if products %}
                                <ul class="category-products">
                                    {% for product in products %}
                                    <li><a href="{{product.Link}}">{{product.Title}}</a></li>
                                    {% endfor %}
                                </ul>
                                {% endif %}
                                {% endarchiveList %}
                            {% endif %}
                        </li>
                    {% endfor %}
                </ul>
                {% endif %}
            </li>
        {% endfor %}
        {% endnavList %}
    </ul>
</nav>

here,inner.PageIdIt is crucial, it will obtain the ID of the category or single page associated with the secondary navigation. We use this ID toarchiveListfilter out the articles or products under the corresponding category.

Case three: Displaying the subcategory list in the navigation dropdown menu

If you want the secondary menu to display all subcategories under a primary category instead of specific documents, you can combinecategoryList.

`

Related articles

How to display the website's Logo, filing number and copyright information in AnQiCMS templates?

When building a professional website, some basic and important information is also indispensable, such as the website logo, filing number, and copyright statement.These elements not only help enhance the professional image and user trust of the website, but are also crucial for complying with specific regional regulations (especially the record-keeping requirements of Mainland China).In AnQiCMS (AnQiCMS), you can easily display this information in website templates through concise template tags.AnQiCMS uses a template engine syntax similar to Django, making the writing of template files intuitive and efficient

2025-11-08

How to batch regenerate thumbnails for AnQiCMS to adapt to new display sizes or formats (such as WebP)?

In website operation, images are indispensable elements to attract visitors and convey information, while thumbnails play a key role in enhancing the beauty of the page and loading efficiency in scenarios such as content lists and article recommendations.But as website design evolves, the diversity of display devices increases, and the demand for performance optimization continues to rise, the original thumbnail size or format may no longer be applicable.For example, to improve the loading speed of the website, convert all images to a more efficient WebP format, or to adapt to the new responsive layout, adjust the thumbnail display size may be required.face this situation

2025-11-08

How to configure the thumbnail processing method of AnQiCMS to ensure the unified display effect of images on the front end?

In AnQiCMS, the unified display effect of images is crucial for the overall aesthetics and user experience of the website, especially for thumbnails.Whether it is an article list, product display, or category page, maintaining the consistent size and style of thumbnails can make the website look more professional and easier to browse.AnQiCMS provides flexible configuration options, allowing us to easily achieve this goal. ### Thumbnail location settings: Content settings are crucial To start configuring thumbnails, we need to log in to the AnQiCMS backend management interface. Find "System Settings" in the left navigation bar

2025-11-08

How to control access and display permissions for different user groups on AnQiCMS to achieve content monetization?

In the practice of content operation, effectively managing different users' access rights to content is a key link in realizing the commercialization of content value.Many content creators and enterprises hope to provide differentiated content services for users at different levels, such as exclusive paid membership, VIP content preview, or unlocking more in-depth information based on user levels.AnQiCMS provides a set of effective and flexible functions that help us easily meet these needs.### Core Mechanism: User Grouping and Content Permission Hierarchy AnQiCMS

2025-11-08

How to batch update display text and links for the 'Full Site Content Replacement' feature of AnQiCMS?

The "Full Site Content Replacement" feature of AnQiCMS: an efficient tool for batch updating website text and links Content updates and maintenance are an indispensable part of daily website operations.It is undoubtedly time-consuming and labor-intensive to manually modify a massive amount of content, whether it is to adapt to a new content strategy, optimize search engine rankings, or simply correct a spelling error or update a broken link.Fortunately, AnQiCMS provides a powerful feature named "Site-wide Content Replacement" which can help users complete these tasks in bulk and efficiently, greatly improving operational efficiency

2025-11-08

How to display custom Banner image and content in AnQiCMS single page?

In website operation, a well-designed single page often plays an important role in brand display, product introduction, or specific event promotion.A striking Banner area that can quickly capture the visitor's attention and convey core information.AnQiCMS as a flexible content management system, provides a very convenient way, allowing you to easily set and display custom Banner images and content on a single page.Next, we will explore how to implement this feature in AnQiCMS.## Step 1

2025-11-08

How does AnQiCMS ensure that mathematical formulas and flowcharts inserted in the Markdown editor are displayed normally on the front end?

In modern website content creation, Markdown is favored by a large number of content creators for its concise and efficient features.However, for websites that need to present complex information, such as mathematical formulas and flowcharts, how to seamlessly insert them into Markdown editors and ensure they are displayed normally on the front end is often a challenge for content operators.AnQiCMS (AnQiCMS) fully understands this need, through flexible configuration and standardized introduction methods, allowing these complex elements to be elegantly presented on your website

2025-11-08

How to use AnQiCMS filter to perform string truncation, case conversion, and other processing on displayed content?

When using AnQiCMS for website content management, we often encounter situations where we need to make some fine adjustments to the displayed content, such as when a title of an article is too long and we want it to be displayed partially with an ellipsis at the end;Or some text should be displayed in uppercase or lowercase. The powerful template filter function of AnQiCMS can easily help us meet these needs without modifying any backend code, and it can be completed directly at the template level.The template filter is a practical tool in AnQiCMS template language, which allows us to transform the values of template variables

2025-11-08