How to implement the hierarchical display of custom navigation menus in Anqi CMS templates?

Calendar 👁️ 62

To implement hierarchical display of custom navigation menus in Anqi CMS is an important aspect for enhancing the user experience and content organization of a website.AnQiCMS provides flexible backend configuration and powerful template tags, allowing users to easily build clear and easy-to-navigate multi-level menu structures.

Backend settings for custom navigation menus

To implement the hierarchical display of the navigation menu, you first need to make the corresponding configuration in the AnQiCMS backend.

In the background management interface, find the 'Background Settings' menu under the 'Navigation Settings' option.This is the core area for managing all navigation links on the website. The system has a default "default navigation" category, which you can edit on this basis, or create a new navigation category, such as "footer navigation" or "sidebar navigation", to meet the display needs of different areas.

After entering a specific navigation category, you can add new navigation links. When adding or editing navigation links, several key settings determine their hierarchical relationship:

  • display nameThis is the text displayed on the front page navigation link, you can name it freely as needed.
  • Link Type: AnQiCMS supports three types of links: built-in links (such as the homepage), category page links (selecting existing articles or product categories), and external links (can link to any URL within or outside the site).Select the appropriate link type to direct navigation to the correct content.
  • Parent navigationThis is the key to achieving hierarchical display. If a navigation link is a top-level menu item, select 'Top-level navigation'.If it is a sub-menu item, you need to select its parent navigation from the dropdown list.The AnQiCMS navigation system currently supports up to two levels of menus, that is, a top-level menu item can contain one level of sub-menus.
  • Display orderYou can control the order of navigation links by setting numbers, the smaller the number, the earlier it is displayed.
  • Subheading nameandNavigation descriptionThese fields can provide additional text information for navigation, making it convenient to display more rich content in templates, such as showing a Chinese title while also displaying an English subtitle.

By setting above, you can build a clear second-level navigation structure, such as: Home, About Us (main menu), Products (main menu) - > Product Category A (second-level menu), Product Category B (second-level menu), News (main menu), etc.

The template calls and displays the hierarchical navigation

After completing the navigation menu settings in the background, the next step is to call these data in the website template and display them hierarchically. AnQiCMS providesnavListTag to get navigation list data.

First, in your template file (for exampleheader.htmlorbase.html), you can usenavListTag to get navigation data. This tag will return an array object containing all navigation items, each of which may contain a namedNavListThe child array is used to store the sub-menus.

A typical call structure is as follows:

{% navList navs %}
<nav>
    <ul class="main-nav">
        {%- for item in navs %}
        <li class="nav-item {% if item.IsCurrent %}active{% endif %}">
            <a href="{{ item.Link }}" {% if item.NavList %}class="has-submenu"{% endif %}>
                {{ item.Title }}
                {% if item.SubTitle %}<span>{{ item.SubTitle }}</span>{% endif %}
            </a>
            {%- if item.NavList %}
            <ul class="submenu">
                {%- for inner in item.NavList %}
                <li class="submenu-item {% if inner.IsCurrent %}active{% endif %}">
                    <a href="{{ inner.Link }}">
                        {{ inner.Title }}
                        {% if inner.SubTitle %}<span>{{ inner.SubTitle }}</span>{% endif %}
                    </a>
                </li>
                {% endfor %}
            </ul>
            {% endif %}
        </li>
        {% endfor %}
    </ul>
</nav>
{% endnavList %}

In the above code example:

  1. {% navList navs %}Retrieved all navigation menus configured on the backend and assigned them tonavsVariable.
  2. The outermost{% for item in navs %}The loop iterates over all top-level navigation menu items.
    • item.Linkanditem.TitleUsed to display the links and text of the top-level menu.
    • {% if item.IsCurrent %}active{% endif %}Can be used to determine whether the current page being accessed matches the navigation item, thereby addingactiveClass name, to achieve the style highlighting of the selected state.
    • {% if item.NavList %}Is the key to determine whether the current top-level menu item has a submenu. If it existsNavListIt indicates that it has a lower-level menu.
  3. Inner layers.{% for inner in item.NavList %}It loops through all the submenus of the current top-level menu item.
    • inner.Linkandinner.TitleUsed to display the link and text of the submenu.

By such a structure, you can flexibly use CSS styles to control the layout of the top-level menu and its submenus, such as using float, positioning, or Flexbox/Grid to implement dropdown menus, sidebar expansion, and other visual effects. You can customize it according to your website design needs, formain-navandsubmenuAdd the corresponding class name and style.

Expand applications and注意事项

In addition to simple link display, you can also combine other tags to achieve a richer navigation experience. For example, if your navigation sub-menu points to a category, you caninner.PageId(If the submenu is associated with a category page) to obtain the list of popular articles or product lists under the category, directly displayed in the dropdown menu, further improving the efficiency of users reaching the content. This istag-/anqiapi-other/165.htmlThe document example is illustrated, that is, product documents or subcategory lists are displayed in the drop-down menu.

Points to note:

  • The navigation menu of AnQi CMS currently supports two levels, if your website design needs a deeper navigation structure, you may need to consider building it through content categories or single pages, and manually calling it in the templatecategoryListnested with tags instead of relyingnavListthe automatic hierarchy function.
  • item.IsCurrentThe property is the key to implementing the "selected" navigation state, ensuring that your CSS can correctly identify and render this state, providing users with clear visual feedback.
  • When modifying templates, it is recommended to back up the original template first and perform tests in a test environment to avoid unnecessary impact on the online website.

By flexibly using the background navigation settings and in the templatenavListA clever combination of labels, you will be able to build a fully functional, well-structured and user-friendly navigation system for your AnQiCMS website.


Frequently Asked Questions (FAQ)

1. Does AnQiCMS navigation menu support three or more levels?The built-in navigation menu feature of AnQiCMS is designed to support up to two levels of hierarchy display (i.e., a top-level menu item can contain one level of submenus). If your website requires a deeper navigation structure, consider combining content categories (categoryListLabels) and custom template logic to implement, but this requires more complex template code to manually construct multi-level nested relationships.

How to set the navigation menu to display submenus only on mouse hover?This is mainly implemented through CSS and a small amount of JavaScript. You can output navigation according to the two-level list HTML structure in the template (such as<ul><li><a></a><ul class="submenu">...</ul></li></ul>),then use CSS (for exampledisplay: none;anddisplay: block;cooperate:hoverpseudo-classes) to control the submenu.submenuThe display and hide. For more complex interactions, such as fade-in and fade-out effects, or to avoid issues with touch devices, it may be necessary to introduce JavaScript libraries such as jQuery to assist.

3. Can I directly display the latest articles or hot products under a specific category in the navigation dropdown menu?Yes, it is achievable. In the template, when a certain navigation item has a submenu or is associated with a category (viaitem.PageIdGet category ID), you can use it nested within the submenu area of the navigation itemarchiveListorcategoryListUse tags to retrieve and display the corresponding latest articles, popular products, or subcategory lists. For example, add one inside the sub-menu.<li>Add another one inside.archiveListUse a loop to display article titles.

Related articles

Does AnQi CMS support rendering Markdown formatted text in the content as HTML?

Anqi CMS is an efficient and customizable content management system that has always been committed to providing modern and convenient solutions in content creation and presentation.For many content creators, Markdown, with its concise and efficient features, has become an indispensable tool for daily writing.Then, does AnQi CMS support Markdown formatted text and render it as HTML to display normally on the front-end page?The answer is affirmative, Anqi CMS provides comprehensive support for Markdown, with high integration and smooth operation. Firstly

2025-11-08

How to set the SEO title, keywords, and description (TDK) of a website to display in search results in Anqi CMS?

## Optimize Search Visibility: Detailed Guide to Fine-tuning Website SEO Title, Keywords, and Description (TDK) in AnQi CMS In the digital world, the visibility of a website is the key to its success.When a user searches for information through a search engine, the way your website is displayed in the search results directly affects whether they will click to enter.This, the website's SEO title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, play a crucial role

2025-11-08

How to crop and process the thumbnail size of articles in AnQi CMS to adapt to different display requirements?

In website content operation, images, especially thumbnails, play a crucial role.They are not only the first line of defense in attracting user clicks, but also the key to adapting to different devices and layout formats.A high-efficiency website content management system should provide a flexible thumbnail processing mechanism.AnQiCMS (AnQiCMS) considers this aspect thoroughly, providing a series of powerful features to help us easily manage and optimize article thumbnails to meet various display needs.### The Source and Intelligence Generation of Thumbnails The acquisition of article thumbnails in AnQi CMS is very flexible

2025-11-08

How to implement dynamic display of breadcrumb navigation in AnQi CMS templates?

In website operation, Breadcrumb Navigation plays a crucial role.It not only can intuitively display the user's position level in the website, helping users understand the relationship between the current page and the entire website structure, but also can effectively improve the user experience, reduce the bounce rate, and have a positive impact on search engine optimization (SEO).For websites built using AnQiCMS, implementing dynamic breadcrumb navigation is a simple and efficient feature enhancement.AnQiCMS as a Go-based

2025-11-08

How does Anqi CMS display the website visitor's comment list and its reply relationship?

When building and maintaining an active website, visitor interaction is a crucial aspect.The comment system not only enhances the discussion热度 of the website content, strengthens user stickiness, but also brings new content to the website and has a positive impact on search engine optimization (SEO).AnQiCMS (AnQiCMS) fully understands this, and therefore its built-in comment feature provides strong and flexible support for displaying comment lists, handling reply relationships, and managing comments.

2025-11-08

How to build and display an online comment form and its custom fields in Anqi CMS?

Aqii CMS provides a powerful and flexible online message function, which not only allows you to build a basic contact form, but also enables you to customize various fields according to business needs, thereby collecting more accurate user feedback.Below, we will explore how to easily build and display these comment forms in Anqi CMS. ### In AnQi CMS backend, configure the message form and custom fields To start building your online message form, you first need to log in to the AnQi CMS backend interface. 1. **Access the Message Management Module:** Log in to the backend after

2025-11-08

How does Anqi CMS handle and display remote images, is it downloaded locally or directly referenced?

In website content management, effective image processing is crucial for improving page loading speed, user experience, and even SEO performance.AnQiCMS (AnQiCMS) provides flexible and practical strategies for handling remote images referenced in content, mainly manifested in two ways: downloading them to the local server for management or directly referencing the original link of the remote image.Both of these methods have their own focus, meeting the needs of different operation scenarios.**The core processing mechanism of AnQi CMS for remote images** AnQi CMS encounters remote image links in the content editor

2025-11-08

How to display the single page content of a specified ID in Anqi CMS, such as 'About Us'?

In AnQi CMS, whether it is to display a corporate profile like "About Us" or static content such as "Contact Information", "Terms of Service", the single-page feature is very practical.It allows you to create independent pages that do not belong to any category and provides a flexible way to control the display of these pages. To make the Anqie CMS display the single page content of a specified ID, you will mainly use the built-in template tags and the page management function of the back-end.This makes it very convenient to customize exclusive layouts at any location on the website or for specific single-page websites.

2025-11-08