How to implement the display of multi-level navigation menus in AnQiCMS and support secondary dropdown menus?

Calendar 👁️ 79

A clear and intuitive navigation system is the key to any website's success, as it can guide visitors to quickly find the information they need and greatly enhance the user experience.AnQiCMS as an efficient content management system provides flexible and powerful features to build and manage website navigation menus, including perfect support for multi-level structures and secondary dropdown menus.

Define your navigation structure in the AnQiCMS backend

The first step in building a multi-level navigation menu in AnQiCMS is to configure it in the backend management interface. You can go to“Background Settings”area, find“Navigation Settings”Option. This is the center where you manage all website navigation.

  1. Navigation category management: Divide navigation areasAnQiCMS allows you to create different navigation categories to meet the needs of different website areas.For example, in addition to the default 'main navigation', you may also need a 'footer navigation' or 'sidebar navigation'.In the 'Navigation Category Management', you can add custom categories as needed according to the website layout.Each category has a unique ID, which is used when calling the front end to ensure that you can display the corresponding navigation at the specified location.

  2. Navigation link setting: Build menu itemsThis is the core link in creating and organizing specific menu items. In the navigation link settings, you can configure the following key information for each menu item:

    • Hierarchy: Implement first and second-level dropdown menusAnQiCMS special supportUp to two-level navigation linksThis means you can easily implement a second-level dropdown menu under the first-level menu. When adding or editing navigation links, through“Parent Navigation”Option to determine its level. If you choose 'Top-level navigation', it will be displayed as a first-level menu;If you select an existing top-level menu as the parent, it will become a secondary dropdown item under that menu.This design makes the menu level clear and controllable, which is very suitable for common website navigation layouts.

    • Display and Description: Create a user-friendly interfaceYou can set for each navigation item“Display Name”, this is the menu text seen by visitors on the website. In addition, you can also add“Sub Title Name”and“Navigation Description”. Although not all templates use these fields, they provide a rich space for customization, making your navigation more informative or visually attractive.

    • Link types: meet diverse directional needsAnQiCMS provides various link types, allowing your navigation to point to any content:

      • Built-in linkIncluding the homepage, article model homepage, product model homepage, etc., for quick access to the core functional pages of the website.
      • Category page linkYou can choose any existing article category, product category, or standalone page as the navigation target, ensuring that the navigation is closely integrated with the website content.
      • External linkIf you need to link to other websites or specific URLs within the site, you can directly fill in external links, with great flexibility.
    • Display order: control the display order of the menuBy settingDisplay orderThe number, you can easily adjust the order of the navigation menu items. The smaller the number, the earlier the menu item is displayed, giving you complete control over the layout of the navigation.

Front-end implementation: utilizingnavListLabel presentation of menu

After the navigation structure is defined in the background, the next step is how to elegantly present them in the front-end template of the website. AnQiCMS provides powerful features for this.navListThe tag, it can provide structured data from the background configuration to the template.

UsenavListWhen using the tag, you can specify the navigation category ID to be called (typeId), for exampletypeId=1usually corresponds to the main navigation. If your website has enabled the multi-site feature, you can alsositeIdParameters to specify which site's data to call.

navListthe tag will return a list object containing all navigation items. Each navigation item (such asitemThese all contain the following important fields:Title(Title),Link(Link),IsCurrent(Whether it is a link to the current page), and a crucial oneNavListfield.NavListIt is also a list that contains all the secondary submenu items of the navigation item, which is the key to implementing a two-level dropdown menu.

This is a simplified and coherent code example that shows how to usenavListtags to build a navigation with a second-level dropdown menu:

<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-dropdown{% endif %}">
                    <a href="{{ item.Link }}" {% if item.NavList %}aria-haspopup="true"{% endif %}>
                        {{ item.Title }}
                    </a>
                    {% if item.NavList %}
                        <ul class="dropdown-menu">
                            {% for subItem in item.NavList %}
                                <li class="dropdown-item {% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

In this code, we first use{% navList navs with typeId=1 %}Obtained all the first-level menu items of the main navigation. Next, by the outer{% for item in navs %}Loop through each first-level menu item. For each menu item, we check{% if item.NavList %}To check if there is a secondary submenu. If it exists, render onedropdown-menuof<ul>and within the{% for subItem in item.NavList %}loop to traverse and display all the secondary submenu items.

Byitem.IsCurrentandsubItem.IsCurrentField, you can easily add the 'active' class or other styles to the corresponding navigation item of the current visited page to highlight the current position, thereby enhancing the user experience.

Advanced Application: Content Display in Navigation

The AnQiCMS navigation system is not limited to simple link jumps, it also supports directly displaying related content in the dropdown menu, such as articles or subcategory lists under specific categories. This requires you to combine in the loop of the secondary menu.archiveListorcategoryList.

For example, if you want to display the latest few articles under the category pointed to by a secondary dropdown menu, you can use it in the loop of the secondary menu itemsubIteminside the looparchiveList:

{# ... (外层navList和item循环) ... #}
                    {% if item.NavList %}
                        <ul class="dropdown-menu">
                            {% for subItem in item.NavList %}
                                <li class="dropdown-item {% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                    {# 假设subItem.PageId是分类ID,且我们想展示该分类下的文档 #}
                                    {% if subItem.PageId > 0 %}
                                        {% archiveList articles with type="list" categoryId=subItem.PageId limit="5" %}
                                            {% if articles %}
                                                <ul class="content-list">
                                                    {% for article in articles %}
                                                        <li><a href="{{ article.Link }}">{{ article.Title }}</a></li>
                                                    {% endfor %}
                                                </ul>
                                            {% endif %}
                                        {% endarchiveList %}
                                    {% endif %}
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
{# ... (外层navList和item循环结束) ... #}

This code demonstrates how to call through a secondary menu item, bysubItem.PageId(usually used to store the category or page ID linked to) to callarchiveListTags, display the latest 5 articles under this category. This method greatly enriches the interactivity and information density of navigation.

By following these steps, you can flexibly build and display multi-level navigation menus in AnQiCMS, achieving an intuitive and feature-rich website navigation experience.


Frequently Asked Questions (FAQ)

  1. Why did I configure the secondary menu, but it did not display the dropdown effect on the website front-end?This is usually due to your website template not adapting the CSS styles or JavaScript interactions for the secondary navigation. AnQiCMS'snavListThe label will correctly output the data structure of the second-level menu (i.e.item.NavList),but the front-end visual effects (such as the dropdown menu displayed on hover) require the corresponding CSS styles and JavaScript code in the template to support. Please check if your template has the relevant style for.has-dropdownor.dropdown-menuDefinition of styles and interactive scripts for the same class.

  2. How to highlight the current visited page in the navigation menu? navListThe tag will iterate over navigation items and set each one.itemProvide one (including first and second-level menu items)IsCurrentField, its value istrueIt indicates the navigation item that corresponds to the current page being visited. You can use conditional judgment in the template{% if item.IsCurrent %}or{% if subItem.IsCurrent %}Then for the<li>or<a>Add a specific CSS class (for exampleactive), and define the highlight effect through CSS styles.

  3. Does AnQiCMS support creating navigation menus with more than two levels (such as three or more)?According to the instructions of AnQiCMS' 'Navigation Link Settings', the system supports it nativelynavigation links up to 2 levels deepThis means the first-level menu and its first-level dropdown menu. If you need a deeper level of navigation structure, you may need to implement custom template logic or combine it with other content display methods, but this usually increases the complexity of template development, and too deep navigation levels may not be recommended in terms of user experience.

Related articles

How to get and display the detailed content of the current article in AnQiCMS template?

Build a content-rich website, the article detail page is undoubtedly the core.It carries the most specific and valuable information on the website, and it is also one of the pages where users spend the longest time and interact most frequently.In AnQiCMS (AnQi CMS), with its flexible template engine and rich tag system, we can easily obtain and elegantly display the detailed content of the current article.

2025-11-07

What ways does AnQiCMS support for sorting the article list display, such as by views or publication time?

The display order of the website content list is one of the key factors affecting user experience and content operation effects.An excellent CMS system should provide a flexible sorting mechanism, allowing operators to freely adjust the display of articles according to content characteristics and promotion strategies.AnQi CMS deeply understands this, providing users with various ways to sort article lists, helping you accurately control content exposure and traffic guidance.### Core Sorting Feature: The Powerful Application of `archiveList` Tag In AnQi CMS

2025-11-07

How to display a document list on the AnQiCMS website based on a specific category ID?

In AnQiCMS, displaying a document list based on a specific category ID is a very basic and commonly used feature, which allows us to flexibly organize and present website content.AnQiCMS's powerful template tag system makes this operation intuitive and efficient.No matter where you want to manually insert a category of documents on a page, or want the entire category page to automatically display the documents under it, the system provides the corresponding solutions.

2025-11-07

How does AnQiCMS display the latest article list on the homepage?

The homepage is the first impression of visitors arriving at the website, and the timely update of the latest article list can effectively enhance the activity and user stickiness of the website.For users using AnQiCMS, displaying the latest list of published articles on the homepage is a basic and important feature, which can be easily achieved through the flexible template tags provided by the system.AnQiCMS with its efficient and customizable features provides users with an intuitive template system.You do not need to delve deeply into the complex backend code, just master its powerful template tag usage

2025-11-07

How to customize the footer information of the AnQiCMS website, such as copyright statement and filing number?

## Custom AnQiCMS website footer information: Copyright statement and record number setting guide The website footer, although at the bottom of the page, is an indispensable area for conveying important information, establishing brand trust, and meeting legal requirements.A clear and complete footer can enhance the professionalism of the website and provide visitors with convenient legal information and contact details.This article will introduce in detail how to customize the copyright statement, filing number, and other information you want to display in the footer of the website in AnQiCMS.

2025-11-07

How to call and display the website logo image in AnQiCMS template?

In website operation, the Logo is not only a visual symbol of the brand, but also an important part of the website's professionalism and user experience.AnQiCMS (AnQiCMS) provides an intuitive and simple way to manage and call the website logo, allowing you to easily display your brand image in all corners of the website.This article will introduce how to set your website logo in the Anqi CMS backend and guide you to accurately and flexibly call and display it in the front-end template, ensuring that your brand image is perfectly presented.### In Anqi CMS backend to set the website logo First

2025-11-07

How to display the links and titles of the previous and next articles on the article detail page?

In AnQi CMS, adding navigation links for the previous and next articles on the article detail page is a key step to enhance the user reading experience and optimize the internal link structure of the website.This not only encourages visitors to browse more content, but also helps search engines better understand the structure of the website.AnQi CMS provides a very intuitive and easy-to-use template tag, allowing us to easily implement this feature.Understanding the "Previous" and "Next" navigation mechanism The template system of Anqi CMS is designed to be very flexible.

2025-11-07

How to configure and display the recommended attributes of articles in AnQiCMS (such as头条, recommendation, slide)?

In AnQiCMS, let your important articles stand out on the website, such as setting them as the headline of the homepage, special recommendation, or slide show, which is a very practical content operation strategy.AnQiCMS offers intuitive features to help you easily manage the recommended attributes of these articles and flexibly display them on the website front-end. ### Backend Configuration of Article Recommendations Configuring article recommendations in the AnQiCMS management backend is a simple and direct process.

2025-11-07