How to implement a multi-level menu and content联动 display on the AnQiCMS website navigation list?

Calendar 👁️ 71

The website's navigation system is like the skeleton of a building, it not only guides users to browse but also directly affects the exposure and search engine optimization of the content.AnQiCMS provides a flexible and powerful navigation management feature, allowing you to easily build multi-level menus and achieve deep integration with website content, thereby enhancing user experience and content distribution efficiency.

Flexible configuration, build a multi-level navigation skeleton

The starting point of implementing multi-level menus in AnQiCMS is in the background navigation settings.You can find all the configuration items related to website navigation under 'Navigation Settings' in the 'Background Settings'.

First, the system provides a default "default navigation" category, but if you have more diverse needs, such as top navigation, footer navigation, sidebar navigation, etc., AnQiCMS allows you to add multiple custom categories through "navigation category management."}This provides your website with great flexibility, allowing for independent navigation structures to be set at different locations.

When adding or editing specific navigation links, several key settings determine the implementation of multi-level menus.Every navigation link can be specified a 'parent navigation', which is the core of building a multi-level menu.If you set the 'parent navigation' to 'top navigation', it will be displayed as a top-level menu;If you choose an existing first-level menu as its parent, it naturally becomes a second-level menu.Currently, AnQiCMS supports up to two-level navigation links, which is enough to meet the needs of most websites.

The setting of the 'Link Type' ensures the联动 of navigation and content.You can choose an "internal link" to point to the homepage or the homepage of a specific model (such as an article, a product)Select the 'Category Page Link' to directly associate with the created article categories, product categories, or single pages;While "external links" provide the greatest degree of freedom, they can point to any URL within or outside the site.These options make your navigation not just simple text links, but a direct reflection of the website's content architecture.

Template implementation:navListThe powerful power of tags

After the navigation structure is configured on the back-end, it needs to be presented in the front-end template next.AnQiCMS uses a syntax similar to the Django template engine, making template creation intuitive and efficient.The core navigation rendering tag isnavList.

By{% navList navs %}Tags, you can get all the navigation data configured in the background.navsA variable is an array containing navigation entries(item) and you can iterate over it to generate the menu.

A typical multi-level menu structure, which can benavListLabel collaborationforeasily implemented with loops and conditional judgments. Eachitemmay contain aNavListProperty, this property is also an array that stores the lower-level menu data of the current navigation item. It can be nested.forLoop, you can perfectly build a second-level menu:

{% navList navs %}
<ul class="main-nav">
    {%- for item in navs %}
        <li class="{% if item.IsCurrent %}active{% endif %}">
            <a href="{{ item.Link }}">{{item.Title}}</a>
            {%- if item.NavList %} {# 判断是否有下级导航 #}
            <dl class="sub-nav">
                {%- 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 code above,item.IsCurrentThe attribute helps you determine whether the current navigation item is the current page, and then addactiveThe class name, enhancing user experience.

Content联动: Make the menu 'alive'.

It may not be enough to just display link text, sometimes you want to directly display dynamic content associated with the menu item when hovering over or clicking on the secondary menu, such as the latest articles or popular products under a certain category. AnQiCMS'snavListLabel combinationarchiveListandcategoryListContent tags that can easily realize this content linkage.

Each navigation itemitemmay contain aPageIdProperty, which is associated with the category or single page ID set in the background. Using thisPageIdYou can dynamically call related content in the second-level menu and even deeper levels.

For example, if you want to directly display the latest product list of the secondary product category menu, you can do it like this:

<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>

This code first traverses the main navigation, if there is a sub-navigation (second-level navigation) under the first-level navigation, it will continue to traverse the second-level navigation. For each second-level navigation item, if it is associated with aPageId(usually the ID of a certain category), will usearchiveListtags to get the latest products under the category (moduleIdshould be adjusted according to the actual product model ID, which is not explicitly given, assuminginner.PageIdThe corresponding product category). In this way, users can preview the related content directly in the navigation menu, which greatly improves the browsing efficiency.

Another common scenario is to display the subcategories of a category in navigation. This can also be done bycategoryListTag implementation:

<ul>
    {% navList navList with 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 %}
                    {% categoryList categories with parentId=inner.PageId %} {# 显示该分类的下级分类 #}
                    {% if categories %}
                    <ul class="nav-menu-child-subcategories">
                        {% for subCategory in categories %}
                        <li>
                            <a href="{{ subCategory.Link }}">{{subCategory.Title}}</a>
                        </li>
                        {% endfor %}
                    </ul>
                    {% endif %}
                    {% endcategoryList %}
                {% endif %}
            </li>
            {% endfor %}
        </ul>
        {% endif %}
    </li>
    {% endfor %}
    {% endnavList %}
</ul>

Here, if a secondary navigation item is associated with a category ID,categoryListThe tag will retrieve and display all subcategories under the category.

Practical skills and precautions

  • Modular template:To maintain the cleanliness and maintainability of the code, it is recommended to place the navigation code snippet separately.partial/Under the directory (for examplepartial/header_nav.htmlThen proceed{% include "partial/header_nav.html" %}The tag is referenced in the main template, which conforms to the template conventions of AnQiCMS.
  • CSS and JavaScript:The final display effect of the navigation menu, including drop-down animations, responsive layouts, etc., all depend on the carefully written CSS styles and JavaScript interaction logic.AnQiCMS provides a flexible template structure, but the specific style and behavior need to be completed by front-end code.
  • Static rules:Ensure your website is static

Related articles

How to set and display search engine friendly TDK (Title, Description, Keywords) for AnQiCMS pages?

Search engine optimization (SEO) is an indispensable part of website operation, and the Title (title), Description (description), and Keywords (keywords) - abbreviated as TDK - of the website page are the foundation of SEO.They are the first step for search engines to understand page content and a key factor for users to decide whether to click on search results.

2025-11-08

How to dynamically display the contact information of the website in AnQiCMS templates?

In website operation, clearly and accurately displaying the website's contact information is a key link in building trust with users and providing support.A contact method that is easy to find and keep updated, which can not only improve the user experience but also help users find you quickly when necessary.AnQiCMS as an efficient content management system provides a very flexible and intuitive way for you to dynamically display and manage this important information in website templates.

2025-11-08

How to correctly call and display the system configuration information in AnQiCMS templates?

Manage website content in AnQiCMS, it is not just to publish articles and products, but also includes the basic information, contact information, SEO metadata and other system-level configurations of the website.These configuration information is usually required to be displayed correctly on all pages of the website, such as displaying the website logo and name in the page header, displaying the copyright and filing number in the footer, or displaying the company's phone number and address on the contact us page.Properly and flexibly invoking these system configurations is the key to ensuring consistency, ease of maintenance, and SEO-friendliness of the website.AnQiCMS uses syntax similar to the Django template engine

2025-11-08

How to display common website elements, such as headers and footers, uniformly through template fragments (partial)?

When managing website content in Anqi CMS, you may find that many pages have similar structures, such as top navigation, footer copyright information, sidebar, or metadata tags, etc.If you have to write this code repeatedly for each page, it is not only inefficient, but also once you need to modify it, you have to search and update it page by page, which takes time and is prone to errors.Fortunately, Anqi CMS provides a very elegant solution - **template fragments (Partial)**, which helps us manage these common elements efficiently and uniformly.###

2025-11-08

How to display the title, category, time, and other core information on the AnQiCMS document detail page?

Manage website content in AnQiCMS, the document detail page is undoubtedly the core interface for users to obtain information.How to make this page both beautiful and informative is a concern for many website operators.Today, let's talk about how to elegantly display the title, category, publication time, and other key information on the document detail page of AnQiCMS.AnQiCMS uses a syntax similar to the Django template engine, which makes it very intuitive to call various data when customizing templates.

2025-11-08

How to filter and display a specific content list based on the 'recommended properties' of the document?

How to effectively organize and display a large amount of content when operating a website is the key to improving user experience and content value.AnQiCMS provides a very practical feature, that is, to refine the management and filtering of content lists through 'recommended attributes'.This not only makes the website content more dynamic, but also helps visitors find the information they are interested in more quickly.### Understanding "Recommended Properties": A Tool for Content Organization In Anqi CMS, when we publish or edit documents, we will find an option called "Recommended Properties"

2025-11-08

How to optimize the display and lazy loading of images and videos in document content?

In today's content-driven internet environment, images and videos have become key elements in attracting users and enhancing page interaction.However, they are often the main culprits that lead to slow website loading and a decline in user experience.As users of AnQi CMS, we are fortunate to have a powerful and flexible system that not only efficiently manages content but also has many built-in features to help us cleverly optimize the display of images and videos, and realize smart lazy loading, so that the content can also 'fly' while ensuring visual effects.

2025-11-08

How to extract and display the first image in the document content as a thumbnail?

In website operation, it is a key to enhance click-through rate and optimize user experience to equip each article or product with an attractive thumbnail.However, manually creating and uploading thumbnails for a large amount of content will undoubtedly take a lot of time and effort.Our company, AnQi CMS, is well-versed in this field and provides us with an intelligent and efficient thumbnail processing solution, making website content management easier. ### The Intelligent Thumbnail Mechanism of AnQi CMS The thumbnail processing mechanism of AnQi CMS is very user-friendly.

2025-11-08