How to create a multi-level navigation with secondary dropdown menus in the AnQiCMS website navigation?

Calendar 👁️ 87

In website operation, a clear and efficient navigation system is the key to user experience and an important part of search engine optimization.AnQiCMS provides flexible navigation settings functionality, allowing website administrators to easily create and manage multi-level navigation menus, including the feature to support secondary dropdown menus.Next, we will together understand how to achieve this goal in AnQiCMS.

Step 1: Configure navigation links in the background

First, you need to log in to the AnQiCMS backend management interface, go to the navigation settings module.

  1. Manage navigation categoriesAnQiCMS allows you to create independent navigation menus for different areas of the website.The system has a default 'default navigation' category, usually used for the main menu of a website.If you want to set different navigation in other places on the website (such as the footer or sidebar), you can click "Custom Navigation Category" to add a new category, such as "Footer Navigation" or "Product Navigation".This way, you can configure a dedicated menu for each area, maintaining the cleanliness and order of the website content.

  2. Create a first-level navigation itemUnder the navigation category you have selected, start adding a first-level navigation link. These are first-level menu items, which will be displayed directly in the website's navigation bar.

    • Parent navigation:When adding a primary navigation for the first time, please select "Top-level navigation", which indicates that it has no parent menu and is independent.
    • Display name:Enter the navigation names that users will see on the website, such as “Products & Services”, “About Us”, “News Center”, and so on.
    • Link Type:AnQiCMS provides various link types for you to choose from:
      • Built-in links:Including the home page, article model home page, product model home page, etc., for quick and convenient pointing to the built-in pages of the system.
      • Category page links:You can choose the created article category, product category, or single page as the navigation link, for example, pointing to the 'Company Introduction' single page or 'Industry News' category.
      • External links:Flexibly add any on-site or off-site links to meet your personalized needs.
    • Display order:Control the order of navigation items by setting numbers, the smaller the number, the earlier it is displayed.
  3. Add a secondary dropdown menu itemTo create a multi-level navigation that supports secondary dropdown menus, the key is to assign the new navigation item to the corresponding primary navigation.

    • Parent navigation:When adding a second-level navigation, do not select 'Top-level navigation', but rather select the corresponding first-level navigation item you have already created from the dropdown list.For example, if your 'Products and Services' is a top-level navigation, then 'Solutions', 'Product Cases', and others can choose 'Products and Services' as their parent navigation.
    • Display name, link type, display order:These settings are similar to creating a first-level navigation item, fill in according to your actual needs. In this way, you can configure multiple second-level dropdown sub-menus for each first-level navigation item.

Step 2: Display navigation in the website template

After the background configuration is completed, you need to call these navigation data in the front-end template files of the website to display them actually on the website. The AnQiCMS template system usesnavListTo complete this task with a label.

Generally, the code for calling the navigation menu is placed in the common header file of the website template (for example,partial/header.htmlorbase.html).

Here is an example of a navigation example with a second-level dropdown menu displayed in the AnQiCMS template:

{% navList navs with typeId=1 %} {# typeId=1 通常指代默认导航,如果创建了其他导航类别,请替换为对应的ID #}
    <ul class="main-nav"> {# 主菜单的UL标签,您可以根据自己的CSS命名 #}
        {%- for item in navs %} {# 遍历所有一级导航项 #}
            <li class="nav-item {% if item.IsCurrent %}active{% endif %}"> {# 为当前活跃的导航项添加active类 #}
                <a href="{{ item.Link }}">{{item.Title}}</a>
                {%- if item.NavList %} {# 检查当前一级导航项是否有子导航(二级菜单) #}
                    <ul class="sub-nav"> {# 二级下拉菜单的UL标签 #}
                        {%- for inner in item.NavList %} {# 遍历二级导航项 #}
                            <li class="sub-nav-item {% if inner.IsCurrent %}active{% endif %}">
                                <a href="{{ inner.Link }}">{{inner.Title}}</a>
                            </li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endnavList %}

Code analysis:

  • {% navList navs with typeId=1 %}This is the tag for calling the navigation list of AnQiCMS.navsIs the variable name you define for navigation data,typeId=1Represents the navigation category with ID 1 (usually the default navigation). If you have created other navigation categories, please specifytypeIdChange to the corresponding ID.
  • {%- for item in navs %}This loop will iterate through all the first-level navigation items configured in your backend,itemThe variable represents each first-level navigation item.
  • {{ item.Link }}and{{ item.Title }}: Output the link address and display name of the first-level navigation.
  • {% if item.IsCurrent %}active{% endif %}: This is a conditional judgment, if the current page matches the navigation item, it will be automatically added.activeThe class makes it easy to highlight the navigation of the current page with CSS.
  • {%- if item.NavList %}This is the key to creating a secondary dropdown menu.item.NavListIt will include all the sub-navigation items of the current top-level navigation (i.e., the second-level navigation you configure in the background). Ifitem.NavListit exists, it means that the top-level navigation has a dropdown menu.
  • <ul class="sub-nav">and{%- for inner in item.NavList %}Here, you can create a new<ul>tag to wrap the second-level menu item and useinnervariable traversalitem.NavListfor each second-level navigation item.
  • CSS and JavaScript:Please note that the above code is mainly responsible for outputting the HTML structure of navigation.To implement the real "dropdown menu" effect, you need to write the corresponding CSS styles to control the hide and show of the secondary menu, and may also combine JavaScript to enhance the interactive experience, such as displaying the dropdown menu when the mouse hovers over it.

Suggestion for optimizing navigation experience

  • Keep it concise:Avoid too deep menu levels, AnQiCMS defaults to two levels which is enough to meet the needs of most websites. Too many levels will make users confused.
  • Clear naming:Navigation names should be intuitive and clear, allowing users to understand the content they point to at a glance.
  • Test compatibility:Test your navigation menu on different devices (PC, mobile, tablet) and different browsers to ensure that it displays and functions correctly.
  • Accessibility:Consider adding ARIA attributes to the navigation menu to improve the friendliness for users of screen readers and other assistive technologies.

By following these steps, you can successfully create and display a multi-level navigation with secondary dropdown menus on the AnQiCMS website, providing your website visitors with a more convenient and user-friendly browsing experience.


Frequently Asked Questions (FAQ)

1. Does AnQiCMS support creating dropdown menus with three or more levels?

The navigation list function of AnQiCMS currently supports up to two levels of navigation links by default, that is, a first-level menu item can contain a second-level dropdown menu.If you need a deeper level of menu, you may need to implement it through custom template tags or by combining with front-end JavaScript, but this goes beyond the scope of the system's built-in navigation settings.

2. I have configured multiple navigation categories (such as main navigation, footer navigation), how can I call them separately in the template?

In the background navigation category management, each navigation category will have a unique ID. Used in the template.navListwhen using tags, you can go throughtypeIdParameters are used to specify the navigation category to be called. For example, if your main navigation ID is 1, and the footer navigation ID is 2, then you can use them separately when calling it.{% navList mainNavs with typeId=1 %}and{% navList footerNavs with typeId=2 %}.

3. Why can't my secondary dropdown menu be expanded on mobile devices, while it displays normally on PC?

This is usually due to the different interaction logic and style handling of dropdown menus between mobile and PC endpoints.On the PC side, the mouse hover is commonly used to trigger the dropdown, while on the mobile side, it usually requires a click to expand.You need to check the CSS and JavaScript code responsible for the display/hide of the dropdown menu, ensuring that it can correctly respond to click events or touch gestures on mobile devices. AnQiCMS

Related articles

How to retrieve and display related article lists based on the current article in AnQiCMS template?

How to intelligently display related article lists in the AnQiCMS template?After we publish an excellent article, it is natural for us to hope that readers will continue to browse more interesting content on the website.This involves the skill of displaying the 'related articles' list at the bottom of the article detail page.A highly recommended relevant article, not only can it effectively extend the user's stay on the website, improve user experience, but also has great benefits for the website's SEO optimization and content in-depth mining.AnQiCMS (AnQiCMS) knows this and provides a very concise and efficient template tag for it

2025-11-07

How to display the title and link of the previous and next articles on the AnQiCMS article detail page?

Managing website content in AnQiCMS and providing users with a smooth browsing experience is one of the key factors in content operation.After a user finishes reading an excellent article, they often hope to easily jump to related or consecutive content, and the "Previous" and "Next" navigation on the article detail page is an important function to meet this need.AnQiCMS provides simple and powerful template tags, allowing you to easily implement this feature on the article detail page.### Easily Achieve

2025-11-07

How to implement pagination for article lists in AnQiCMS templates?

Good, as an experienced website operations expert, I know that implementing pagination for the article list in AnQiCMS not only improves user experience and makes content browsing smoother, but also helps with search engine optimization, allowing website content to be indexed better.Next, I will combine the AnQiCMS template mechanism and explain in detail how to easily implement this feature.

2025-11-07

How to display the article list on the AnQiCMS website and support sorting by publish time in descending order?

When running a website, effectively displaying a content list is a key factor in attracting visitors and enhancing user experience.For friends using AnQiCMS, the system provides very flexible and powerful template functions, which can easily meet various complex content display needs.Today, let's discuss how to display the article list on the AnQiCMS website, ensuring that the articles are sorted from the most recent to the oldest in publication time, while also supporting friendly pagination features.AnQiCMS's template system borrows the syntax of Django template engine

2025-11-07

How to display the breadcrumb navigation path of the current page in AnQiCMS template?

In website operation, a clear navigation path is crucial for user experience.Breadcrumb Navigation is like a clue in real life, clearly showing the user's current position on the website, allowing them to easily see where they are and quickly return to the previous or higher-level page.This not only helps users quickly understand the website structure and improve user experience, but also greatly benefits search engine optimization (SEO), as it helps search engines better understand the hierarchical structure of the website. AnQiCMS

2025-11-07

How to display all articles under a specific category in the AnQiCMS template?

When building a website with AnQiCMS, we often need to make the page content more flexible to meet the display needs of different blocks.One of the most common needs is how to accurately display a list of all articles under a specific category in the template.AnQiCMS with its efficient architecture based on the Go language and similar Django template engine syntax makes this task both intuitive and powerful.

2025-11-07

How to retrieve and display detailed information about a category, such as the category title, description, and thumbnail, in AnQiCMS?

In AnQi CMS, obtaining and displaying detailed information of a category is an indispensable part of building a dynamic website. Whether it is used to create a category list, a category special page, or display the information of the category in the article detail page, AnQi CMS provides simple and powerful template tags to achieve this. <h3>Deeply understand the `categoryDetail` tag</h3> AnQi CMS template system adopts a syntax similar to Django, where `categoryDetail`

2025-11-07

How to display all single page lists on AnQiCMS template?

In website operation, we often need to create some independent pages, such as "About Us", "Contact Information", "Terms of Service", or some special introduction pages.These pages are usually called "single-page", their content is fixed, they do not belong to the conventional article or product categories, but they are an indispensable part of the website.When you have accumulated a large number of single pages on your website, you may wish to display a list of these single pages in a specific location, such as the bottom of the website, the sidebar, or even on a dedicated page, to facilitate browsing and searching for visitors.

2025-11-07