How to build and display a multi-level website navigation menu in AnQiCMS?

Calendar 👁️ 63

In website operations, a clear and intuitive navigation menu is the core of user experience, it not only guides visitors to find the information they need quickly, but is also an important part of website structure and SEO optimization.AnQiCMS as an efficient enterprise-level content management system, provides flexible and powerful navigation menu construction and display functions, helping you easily manage the hierarchical structure of your website.

1. Build the navigation menu in the AnQiCMS background

The first step in building a multi-level navigation menu is to manage it centrally in the AnQiCMS backend.You can find the 'Navigation Settings' option in the 'Background Settings' area, which is the configuration center for all website navigation.

Firstly, you may need to define different navigation areas, such as "top main navigation", "footer navigation", or "sidebar navigation".AnQiCMS supports creating and distinguishing these navigation areas through 'Navigation Category Management'.There will be a 'default navigation' category by default, you can add 'footer navigation' and other such according to your needs, so that independent menu lists can be provided for different positions of the website.

Continue, add specific navigation links for each navigation category. In the 'Navigation Link Settings', you can flexibly configure each menu item.

  • Display name and auxiliary information:Each menu item has a 'display name', which is the text shown to the user on the front end.If you need a richer display, you can also set the 'sub-title name' and 'navigation description', this information can be called in the template.
  • Link Type:AnQiCMS provides various link types to meet the needs of different content directions:
    • Built-in links:Contains home page links, article model home page, product model home page, and other preset links for quick reference.
    • Category page links:Allow you to directly select the created document category or single page as a menu item, and the navigation links will also be automatically synchronized when this content is updated.
    • External links:If you need to point to external content or a custom internal URL, you can select this option and freely fill in the target address.
  • Build a multi-level structure:AnQiCMS supports navigation menus up to two levels.By setting the "parent navigation" of the menu item, you can easily specify a link as a submenu under the first-level navigation.For example, if you have a 'Product' top-level navigation, you can add 'Product A', 'Product B', and so on as secondary menu items below it.
  • Display order:Each menu item can be set to 'Display Order', the smaller the number, the earlier it appears, making it easy for you to adjust the order of the menu items.

Configure these settings, and you can clearly plan and build a multi-level navigation system that conforms to the website structure in the background.

Secondly, display the multi-level navigation in the front-end template.

After the menu configuration of the background is completed, the next step is to present these meticulously designed navigation menus on the front page of the website.AnQiCMS's template engine uses syntax similar to Django, allowing front-end developers to intuitively call and render backend data.

The core label to display the navigation menu isnavList. Use this label to call the corresponding menu data based on the navigation categories previously defined in the backend.

{% navList navs %}
    <ul>
        {%- 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 %}
    </ul>
{% endnavList %}

In the above code snippet:

  • {% navList navs %}Will retrieve all first-level menu items under the specified navigation category and assign them tonavsVariable.
  • The outermost{% for item in navs %}Loop used to iterate over all first-level menus.
  • {{ item.Link }}and{{ item.Title }}Used to output the link and display name of the menu item.item.IsCurrentIt can help you determine whether the current page you are visiting matches the menu item, thereby addingactiveTo highlight the class name.
  • {%- if item.NavList %}Is to determine whether there is a secondary submenu under the current first-level menu item. If there is, it will enter the inner layer.{% for inner in item.NavList %}Loop, traverse, and display all second-level menu items, which are similar to the first-level menu items.

Expanded Application: Display content in the navigation dropdown menu.

The strength of AnQiCMS lies in the fact that you can not only display simple second-level menus, but also further integrate and display other dynamic content in the dropdown area of navigation, such as the latest products under a certain category or subcategory lists. This is usually done by combiningnavListtags,archiveList(Document list) label andcategoryListlabel to implement the (category list)

Suppose you want to display some of the latest products under the "Electronics" category directly when the secondary menu (such as "Electronics") under the primary menu (such as "Product Center") drops down:

<ul>
    {% navList navList with typeId=1 %} {# 假设typeId=1是您的主导航 #}
    {%- for item in navList %}
    <li>
        <a href="{{ item.Link }}">{{item.Title}}</a>
        {%- if item.NavList %}
        <ul class="nav-menu-child">
            {%- for inner in item.NavList %}
            <li>
                <a href="{{ inner.Link }}">{{inner.Title}}</a>
                {% if inner.PageId > 0 %} {# 判断二级菜单是否关联了某个分类ID #}
                    {% archiveList products with type="list" categoryId=inner.PageId limit="8" %} {# 调用该分类下的8个最新产品 #}
                    {% if products %}
                    <ul class="nav-menu-child-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>

In the above example,inner.PageIdCan get the category ID associated with the second-level menu, then we can use this ID toarchiveListTag the latest products under this category for display. Similarly, if you want to display the subcategory list, just putarchiveListReplacecategoryListJust do it.

Through these flexible backend configurations and template tags, AnQiCMS makes building and managing multi-level website navigation intuitive and efficient. No matter how complex your website structure is, you can easily achieve a clear user-oriented navigation.


Frequently Asked Questions (FAQ)

Q1: Why does my navigation menu only display two levels, and I want more hierarchical menus?AnQiCMS in the background "navigation settings" supports by default the navigation menu structure of up to two levels (that is, the first-level menu and its sub-menus of the next level).If your business truly needs a menu with more than two levels, we usually suggest reconsidering the complexity of navigation, as deep levels may pose challenges to user experience and mobile adaptation.If there are still special requirements, you can consider combining a "single-page" or "document category" page, and display the deeper level content index in the content area of the page in other ways (for example, a sidebar tree menu).

Q2: How to display the latest articles or products in the dropdown menu of the navigation?In the front-end template, you cannavListWhen looping through first or second-level menu items, determine if the current menu item is associated with a category (viaitem.PageIdorinner.PageIdobtaining the category ID), then usearchiveListtags (used for articles or products) orcategoryListLabels (used for subcategories) to dynamically call and display the content of the category. The key is to pass the menu itemPageIdasarchiveListorcategoryListofcategoryIdthe parameter.

Q3: Can I set different navigation menus for different areas of the website (such as the header, footer)?Yes, AnQiCMS fully supports this. You can create multiple independent navigation categories, such as 'Top Navigation' and 'Footer Navigation', under 'Navigation Settings' in the 'Background Settings'.Each category can have its own menu items and structure. In the frontend template, you just need to callnavListwhen using tags, bytypeIdThe parameter specifies the corresponding navigation category ID, which can display different menu lists at different locations.

Related articles

How to control the thumbnail size and cropping method in AnQiCMS template?

When building and operating a website, the presentation of images often directly affects user experience and the professionalism of the site.AnQiCMS (AnQiCMS) fully understands this and provides users with a powerful and flexible thumbnail control function, allowing you to precisely manage the display of images on the website front-end according to your actual needs.This article will introduce in detail how to achieve fine-grained control over the thumbnail size and cropping method of images in Anqi CMS through backend settings and template calls.### Backend sets thumbnail rules unification

2025-11-08

How does AnQiCMS automatically convert uploaded images to WebP format to speed up loading?

In website operation, the speed of image loading is often a key factor affecting user experience and search engine ranking.A lightweight, high-quality image can make a website stand out among competitors.AnQiCMS knows this need and has built-in functionality to automatically convert images to WebP format, making image optimization unprecedentedly simple.

2025-11-08

How to call and display the category Banner image in AnQiCMS template?

In website operation, configuring unique banner images (Banner) for different category pages is an important means to enhance user experience and brand recognition.AnQiCMS provides an intuitive way to manage and call these categorized banner images, making your website visually richer and more professional. ### In the background, set the Banner image for the category Firstly, we need to upload the Banner image for the target category in the Anqi CMS background.This process is very simple: 1. Log in to your Anqi CMS backend management interface.2

2025-11-08

How to set the default thumbnail for AnQiCMS and automatically display it when there is no image in the article?

In website content operation, maintaining the unity of visual style is crucial for enhancing user experience.Especially for the article thumbnail, if some articles are missing images, blank spaces or placeholders appear on the page, which makes it look unprofessional.AnQiCMS (AnQiCMS) provides us with a very practical feature that allows us to easily set a default thumbnail, ensuring that even if the article does not have a dedicated image, it can automatically display a preset image, maintaining the beauty and consistency of the website interface.

2025-11-08

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

Build a user-friendly, SEO-friendly website in AnQiCMS, breadcrumb navigation is an indispensable element.It can clearly show the user's current location, help the user quickly backtrack, and provide valuable website structure information for search engines.AnQiCMS's powerful template engine provides a simple and efficient way to dynamically generate these navigation paths.AnQiCMS's template system adopts syntax similar to the Django template engine, which makes it very easy for content developers to control the display of page content through tags and variables

2025-11-08

How does AnQiCMS display the comment list on article or product detail pages?

In website operation, user interaction is an important link to enhance the value of content and the level of website activity.The comment function serves as a bridge for users to directly communicate with content, not only enriching the page content, but also bringing unique UGC (User Generated Content) to the website, enhancing the community atmosphere, and also positively affecting search engine optimization (SEO).AnQiCMS (AnQiCMS) provides a powerful and flexible comment list display feature, allowing you to easily display user comments on articles or product detail pages and manage them effectively.

2025-11-08

How to call and display the form fields submitted by users in the AnQiCMS template?

AnQi CMS provides a flexible mechanism to handle the interactive content of websites, among which the message form is an important bridge for communication with users.When we need to collect diverse information from users, we often create custom message fields.How to accurately call and display these custom form fields configured in the backend template on the website's frontend, which is the key to achieving personalized user experience.In AnQiCMS, the display of the message form fields mainly depends on the use of template tags.

2025-11-08

How to display the Tag list associated with the article in AnQiCMS?

In AnQiCMS, effectively managing and displaying the tag (Tag) list of articles can not only help with content organization but also significantly improve the internal link structure and search engine optimization (SEO) effect of the website.Labels as a flexible classification method can link articles across categories and themes, providing users with a richer browsing path. ### Manage and create article tags in the background First, understanding how to add and manage article tags in the AnQiCMS background is fundamental.

2025-11-08