How to display a website navigation menu and support multi-level dropdown navigation?

Calendar 👁️ 66

As a senior security CMS website operations person, I know that a well-organized, easy-to-use navigation menu is crucial for the website's user experience and content discovery.The AnQi CMS provides powerful and flexible navigation management functions, which can help us easily set up the main menu of the website and also support multi-level dropdown navigation to meet the needs of complex website structures.

Back-end navigation configuration: Build menu structure

In Anqi CMS, the setup of the navigation menu starts from the backend management interface. We need to accessBackend homepageThen enterBackend settings, and selectWebsite navigation settings. Here is the core area where we manage all the website navigation links.

First, AnQi CMS allows us to create multiple navigation categories based on different layout requirements.For example, we can set independent categories for main navigation, footer navigation, or sidebar navigation.This is completed by adding a new category in the "Navigation Category Management", each category has its uniquetypeIdUsed for subsequent template calls. In this way, we can define independent menu structures for different areas of the website, greatly increasing the flexibility of the website layout.

After selecting or creating a navigation category, we can add specific navigation links.Each link can be set to display a name, which is the menu text displayed on the front-end page;“Subtitle Name” and “Navigation Description” can be filled as needed to accommodate more complex design requirements.The core lies in the selection of 'link type', Anqi CMS supports three types of links:

  • Built-in linkFor example, home page links, article model home page, product model home page, etc., these are the commonly used links preset by the system.
  • Category page link: We can select existing article categories, product categories, or single pages as navigation links, and the system will automatically generate the corresponding link addresses.
  • External linkThis provides great flexibility, allowing us to manually input any custom URL, whether it is an internal link or an external website link.

To implement multi-level dropdown navigation, the key is to use the 'parent navigation' field.When adding or editing a navigation link, if you select an existing top-level navigation item as its 'parent navigation', then the new link will become a submenu item under that top-level navigation.The AnQi CMS native backend navigation settings support up to two levels of navigation links, that is, a main menu item with a sub-menu at the next level.This means we can easily construct the structure of 'Main Menu -> Dropdown Submenu', which is sufficient to meet the hierarchical display needs of the vast majority of websites.By the "Display Order" field, we can flexibly adjust the arrangement order of navigation items, with smaller numbers appearing earlier for fine-grained control.

Front-end template call: display dynamic navigation

After configuring the background navigation, you need to call and display these menus in the front-end template file next. The Anqi CMS template engine is similar to Django syntax, and the template files are usually located under the root directory of the website./templateIn the catalog. We can write the HTML structure here and dynamically obtain the navigation data configured in the background through the tags provided by Anqi CMS.

The core template tags arenavListIt is used to get all the link data for a specified navigation category. For example, to get the menu data for the default navigation category, we can call it like this:

{% navList navs %}
    {# 导航HTML结构将在这里生成 #}
{% endnavList %}

navListThe tag returns an array object containing navigation items (as shown in the example isnavs)。Each navigation item (such asitemvariable) may contain the following key fields:

  • Title: The display name of the navigation item.
  • Link: The link address of the navigation item.
  • IsCurrent: A boolean value indicating whether the current navigation item is the current page.
  • NavList: This is the key to implementing multi-level navigation, if the current navigation item has a submenu,NavListIt will be an array containing submenu items.

To construct a multi-level dropdown navigation HTML structure, we can use nestedforLoop to traverse the main menu items and their sub-menu items. When a main menu item'sitem.NavListfield exists, it means it has a sub-menu, and we can render the second-level menu.

Here is a basic code example showing how to build a two-level dropdown navigation menu in a template:

<ul class="main-nav"> {# 主菜单容器,这里通常是header.html的一部分 #}
    {% navList navs %}
        {%- for item in navs %} {# 遍历一级导航项 #}
            <li class="nav-item {% 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>

Please note that the above code mainly provides the HTML structure for the navigation dropdown effect and responsive layout.You still need to write the corresponding CSS styles and JavaScript interaction code.This usually involves

Related articles

How to dynamically set and call the SEO title, keywords, and description (TDK) of the current page in the template?

As an experienced CMS website operation personnel in a cybersecurity company, I am well aware that high-quality content and excellent search engine optimization (SEO) are the foundation of a website's success.Among them, the SEO title (Title), keywords (Keywords), and description (Description) of the page, abbreviated as TDK, play a vital role.They are not only the key for search engines to understand the content of a page, but also an important factor in attracting users to click.In Anqi CMS, we have flexible and powerful mechanisms to dynamically set and call these TDK information

2025-11-06

How to obtain and display the contact information, phone number, email, WeChat, and other contact methods set in the background?

Hello, as an experienced CMS operation person in the security industry, I know that clear and convenient contact information on the website is crucial for user experience and business conversion.Today, let's discuss in detail how to configure contact information in the Anqi CMS backend and display it flexibly and accurately on various positions of the website front-end. Configure website contact information: Back-end operation guide Managing website contact information in AnQi CMS is an intuitive and powerful process.First, we need to enter the background management interface for configuration.

2025-11-06

How to call and display the name, Logo, and other system global configuration information in AnQi CMS template?

As an experienced security CMS website operations personnel, I am well aware of the importance of the global configuration information of the website, such as the website name and logo, for the unified display of the brand image and user recognition.In AnQi CMS, these core information is unifiedly managed, and through a concise and efficient template tag mechanism, it allows operators to easily call and display on various pages of the website. ### Management of website global configuration information in AnQi CMS AnQi CMS centralizes the global configuration information of the website in the "Global Function Settings" module of the background.

2025-11-06

How to implement template customization for specific categories or pages, for example `page/about.html`?

As an experienced CMS website operator, I am well aware of the importance of content presentation for user experience and Search Engine Optimization (SEO).AnQiCMS provides a powerful and flexible template customization mechanism, allowing us to create exclusive visual and functional layouts based on different content types or specific page requirements.Today, I will detail how to implement template customization for specific categories or pages in AnQiCMS, such as the needs we often encounter, such as `page/about.html`.

2025-11-06

How to correctly generate and display breadcrumb navigation on a page?

As an experienced CMS website operation person in an enterprise, I am very clear about the importance of breadcrumb navigation in improving user experience and website SEO.It not only helps visitors clearly understand their position on the website, but also guides search engines to better understand the website's hierarchical structure.In AnQi CMS, correctly generating and displaying breadcrumb navigation is a fundamental and important content management task.

2025-11-06

How to get the classification list under a specific content model (such as articles, products)?

As an experienced CMS website operation personnel for Anqi, I know the importance of content organization and user experience for the success of the website.Accurately display content categories, not only can help users quickly find the information they are interested in, but also improve the overall SEO performance of the website.Today, we will delve into how to obtain the category list under specific content models (such as articles, products) in AnQiCMS, which is crucial for building clear website navigation, content aggregation modules, and special pages.

2025-11-06

How to retrieve detailed information for a specified category, such as the category name, description, and link?

As an experienced website content expert in AnQiCMS (AnQiCMS) operation, I fully understand the importance of classification information in building website structure and improving user experience.The Anqi CMS, with its intuitive and powerful template tag system, makes it exceptionally easy to obtain and display detailed information about categories.In order to optimize navigation, enrich page content, or improve SEO effect, accurately obtaining the category name, description, and link is an indispensable part of our daily operation.

2025-11-06

How to get the list of all single-page lists of a website?

As an experienced CMS website operation personnel of an enterprise, I know the importance of acquiring and managing website content, especially for single pages carrying core information such as 'About Us', 'Contact Information', or 'Terms of Service'.In AnQi CMS, the system provides an efficient and flexible way to obtain the list of these single pages, so that we can integrate them into website navigation, site map, or other display locations.

2025-11-06