How to display a second-level dropdown menu in the navigation menu and associate different content?

Calendar 👁️ 101

AnQi CMS provides a直观而强大的导航菜单管理系统,allowing you to easily build clear, user-friendly navigation structures for your website, including multi-level dropdown menus.This not only improves the user experience of the website, but also helps search engines better understand the hierarchy of your website content, thereby optimizing SEO performance.

Understanding the navigation system of AnQi CMS

In Anqi CMS, the settings and management of the navigation menu are all concentrated in the "Website Navigation Settings" feature of the background.This is the core area where you build the website menu. The Anqi CMS navigation system allows you to create different types of navigation categories, such as main navigation, footer navigation, or sidebar navigation, and each navigation category supports up to two-level menu structures, that is, a level one main menu and its corresponding level one dropdown submenu.

This design makes content organization more flexible, you can aggregate related content under the same parent menu, display it to visitors in the form of a drop-down menu, which maintains the interface tidy and makes it convenient for users to quickly find the information they need.

Backstage settings: the foundation for building secondary menus

To start setting up the secondary dropdown menu, you first need to enter the "Background Settings" area of the Anqi CMS backend, and then select "Website Navigation Settings".

  1. Manage navigation categories:By default, the system will have a 'default navigation' category.If you need to set up independent menus for different areas of the website (such as the main navigation, footer, etc.), you can add new categories through the "Navigation Category Management" feature.For example, you can add a new category named 'Footer Navigation'.Each category will have an independent navigation link set.

  2. Configure navigation links:Under the selected navigation category, you can start adding and organizing navigation links.

    • Create a first-level navigation:First, add the main menu item of your website. When adding a new link, set the 'Parent Navigation' option to 'Top Level Navigation'.These will be the main entries displayed on the navigation bar of your website.
    • Create a secondary dropdown menu:Next, add a submenu to each top-level navigation item that requires a dropdown function.When adding these submenu items, the key is to set the 'Parent Navigation' option to the corresponding top-level navigation item.These links will automatically be assigned to their parent menu and form a dropdown effect.When configuring each navigation link, you will find that the 'Link Type' provides multiple options, which is the key to associating different content:
      • Built-in links:Home page suitable for linking to the website's homepage or a specific content model (such as articles, products).
      • Category page links:This is the most commonly used content association method. You can directly select the 'document category' or 'single page' you have created as the navigation target.When you select a category, the navigation link will automatically direct to the page of that category;Select a single page to link to that page. This way, your dropdown menu can directly guide users to access specific content lists or information pages.
      • External links:Allow you to link to any custom URL within the site or external websites, providing great flexibility.
    • Adjust display order:You can use the "Display Order" field to control the arrangement of navigation items in the menu. The smaller the number, the earlier it is displayed, which helps you finely adjust the menu layout.

Through the above background configuration, you have already defined a clear hierarchy and content direction for the website's navigation menu.

Template implementation: Let the navigation 'move' on the front page.

After setting up the navigation links on the backend, you still need to call these data in the frontend template files so that they can actually display on the website.AnQi CMS uses a template engine syntax similar to Django, making template development simple.

  1. Locate the template file:usually, the header navigation menu of a website is defined in a public template file, such as/template/您的模板名称/partial/header.htmlor/template/您的模板名称/bash.htmlin such files.

  2. UsenavListTags:AnQi CMS providesnavListTemplate tag to retrieve the navigation list data configured in the background. This tag will return a structured data containing navigation items and their sub-items.

    Here is a general example code snippet that shows how to usenavListtags to render a menu structure with secondary dropdowns:

    <nav class="main-navigation">
        {% navList navs with typeId=1 %} {# 假设 typeId=1 是您的主导航类别 #}
        <ul>
            {%- for item in navs %} {# 遍历一级导航项 #}
                <li class="{% if item.IsCurrent %}active{% endif %}">
                    <a href="{{ item.Link }}">{{item.Title}}</a>
                    {%- if item.NavList %} {# 判断当前一级导航是否有子菜单 #}
                        <ul class="sub-menu"> {# 下拉菜单容器 #}
                            {%- for subItem in item.NavList %} {# 遍历二级导航项 #}
                                <li class="{% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{subItem.Title}}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
        {% endnavList %}
    </nav>
    

    In this code block,{% navList navs with typeId=1 %}Will get all navigation data under the navigation category with backend ID 1. Outer layerforLoop through the first-level navigation items, the inner layer.{%- if item.NavList %}Is the key to determine whether there is a submenu under the current main menu item. If there is, it will render asub-menulist, and then iterate through theforto display all the second-level submenu items.

    Further expand:In addition to simple sub-menus, you can also display more rich content in the drop-down menu according to your needs. For example, under the second-level menu items, you can usecategoryId=subItem.PageIdCombinearchiveListTags, directly display the list of popular articles or products under the category, greatly enhancing the navigability. When setting navigation links in the background, if you select “Category Page Link”,subItem.PageIdIt will automatically have the corresponding category ID, making it convenient for you to call in the template.

Associate with different types of content: the flexibility of navigation.

The AnQi CMS navigation system demonstrates extremely high flexibility in content association. When configuring navigation links in the background, you can freely choose to associate navigation items with:

  • Built-in pages:like the home page or the list page of a specific content model.
  • specific categories or single pages:When you associate a dropdown menu item with a category of articles, products, or specific pages such as "About Us", "Contact Us", etc., the system will automatically handle its URL. In the template, you just need to{{item.Link}}or{{subItem.Link}}It can correctly refer to the addresses of these pages. If necessary,item.PageIdorsubItem.PageIdIt can also further help you obtain detailed information about the category or single page in the template, such as displaying the list of articles under the category, etc.
  • External website or custom URL:For situations where you need to link to external resources or specific custom URLs within the site, you can also fill it directly.

This flexible content association mechanism allows you to create a clear and informative navigation menu based on the overall content structure of the website and the habits of user access.

Summary

Through the navigation management function of Anqi CMS, you can conveniently and quickly create and maintain multi-level dropdown menus, effectively organizing the website content. From the background navigation category management, link configuration, to the front-end template'snavListTag application, every step aims to provide an efficient and flexible solution to help your website better serve users and achieve better online performance.


Frequently Asked Questions (FAQ)

  1. Can the navigation menu only have two levels?Yes, the AnQi CMS built-in navigation management function currently supports the original two-level menu structure, that is, one main menu item and its first-level drop-down submenu.This design is for the simplicity of meeting the needs of most websites and user experience.If you need a deeper level of navigation structure, you may need to implement it through custom templates or by combining with frontend JS/CSS, but this goes beyond the native support of the system.

  2. Why did I set up a secondary menu, but the front-end website did not display it?This is usually because the front-end template file did not call or render the data of the second-level menu correctly. Please check the following points:

    • Are the template tags used correctly:Confirm that your template file uses{% navList ... %}the tag and correctly traverse it insideitem.NavListto display the submenu items.
    • CSS style issues:Even if the data is rendered correctly, if there is a lack of corresponding CSS styles to control the display of the dropdown menu (such as default hidden, displayed when the mouse hovers), the user may also not be able to see it.Make sure your CSS file includes styles for handling dropdown menu display/hide, layout, etc.
    • Cache problem:Sometimes system cache or browser cache may cause changes not to be displayed in time, try clearing the Anqie CMS backend cache and browser cache.
  3. Can I make the secondary menu directly display the list of articles or products under a certain category?Of course. In the template, when you iterate through the secondary menu itemsubItemthen,

Related articles

How to loop through and display all subcategories under a specified category in a template?

How to elegantly display all subcategories under a specified category in Anqi CMS template?For a content-rich website, a clear classification structure is the key to improving user experience and search engine friendliness.AnQiCMS (AnQiCMS) takes advantage of its flexible template engine and powerful tag system, allowing you to easily traverse and display all subcategories under a specified category on the website front end, whether it is a direct subcategory or a multi-level nested subcategory, you can handle it with ease.Today, let's discuss how to implement this feature in Anqi CMS templates.

2025-11-09

How to embed a comment list on the page and control its pagination display?

In website operation, user interaction is the key to enhancing site activity and content value.AnQiCMS provides a set of intuitive and powerful features that help us easily embed comment functions in pages and flexibly control the display of comment lists, especially its pagination management, which is crucial for pages with a large number of user comments. ### Enable comment functionality to bring content to life Firstly, we need to ensure that the comment functionality is enabled on the backend so that users can post comments.Once the comment feature is activated

2025-11-09

How to enable Markdown rendering and correctly display mathematical formulas and flowcharts in AnQiCMS?

In AnQiCMS, if you want to make your content more expressive, especially when it comes to displaying complex mathematical formulas or clear flowcharts, it is a very effective solution to flexibly use the Markdown editor.The new version of AnQiCMS has provided good support for this.Next, we will explore together how to enable these features in AnQiCMS, making your website content come alive.

2025-11-09

How to display additional field data in the front-end template after customizing the content model?

AnQiCMS with its flexible content model function has brought great convenience to us in managing various types of website content.Whether it is an article, product, event, or any other content type that requires special fields, we can easily customize fields in the background to meet unique business needs.But when we eagerly create new fields in the background and fill them with data, new problems also arise: How can we accurately display these newly added custom field data on the front page of the website for visitors?Don't worry, AnQiCMS

2025-11-09

How to specify an independent template file for content display for a specific category or single page?

In a content management system, we often need to present certain specific content of the website in a unique way, which not only meets the specific needs of branding or marketing, but also brings an optimized browsing experience for visitors.Our CMS is well-versed in this, providing flexible template customization features, allowing us to easily specify a unique template file for a category page, or even a single content page.Why do you need to customize the template for a specific page?

2025-11-09

How to use Tag tags to display related article lists on the page?

In website content operations, how to efficiently organize content, improve user experience, and optimize search engine rankings is a key focus for every operator.AnQiCMS as an enterprise-level content management system provides powerful and flexible functions to meet these needs, among which the Tag label function is an indispensable part.Tag label, simply put, is a keyword or thematic word, which can link scattered article content on a website according to common themes or focus points.Reasonably utilizing Tag tags can not only make it easier for users to discover content of interest

2025-11-09

How to configure and display the global contact information of the website, such as phone number, address, WeChat QR code?

In website operation, clearly and accurately displaying contact information is a key link in building user trust and improving service efficiency.Whether it is a phone number, address, email, or the popular WeChat QR code, AnQiCMS provides a flexible and convenient way to configure and manage these global information to ensure they can be presented efficiently on the website. ### Backend Configuration: Centralize your global contact information To centralize this information, you need to log in to the AnQiCMS admin interface. After logging into the backend, please navigate to the left menu bar of “**Backend Settings**”

2025-11-09

How does AnQiCMS handle uploaded images to optimize front-end loading speed and display quality (such as Webp, automatic compression)?

In today's fast-paced online world, website loading speed and content display quality directly affect user experience and search engine rankings.Images are an important part of a website's content, and their handling is crucial for website performance.AnQiCMS (AnQiCMS) fully understands this, and therefore provides a series of powerful and practical functions in terms of image upload and management, aimed at helping us easily optimize the front-end loading speed and improve the display quality of images.### Core Strategy: Convert to WebP format, improve loading efficiency The choice of image format has a significant impact on website performance

2025-11-09