How to build a multi-level website navigation menu using the `navList` tag and support dynamic display of categories or document links?

Calendar 👁️ 60

As an experienced website operations expert, I am well aware of the importance of a clear and efficient website navigation system in enhancing user experience, guiding content consumption, and optimizing search engine rankings (SEO).In AnQiCMS (AnQiCMS), such a well-designed content management system, building flexible and variable navigation menus, and enabling it to intelligently display dynamic content, is the key to operators achieving fine-grained content layout.Today, let's delve deeply into Anqi CMSnavListThe mystery of the tag, see how it helps us achieve this goal.

navListTag: The cornerstone of website navigation.

In AnQi CMS,navListTags are the core tools for building website navigation menus. They do not simply pull static links, but cleverly combine the background configuration of navigation structures with front-end template rendering, allowing us to create menus ranging from simple single-level menus to complex secondary (even more levels) dropdown menus, and seamlessly connect with the website's categories or document content to achieve truly dynamic navigation.

Imagine your website as a large shopping mall, and the navigation menu is like the signposts of the mall.A clear and intelligent sign can help customers quickly find the products they like, while a chaotic sign will only make people lose their way.navListThe label is exactly the powerful brush provided by AnQi CMS for us to draw such an intelligent sign.

Backend first: the basic construction of the navigation menu.

While usingnavListBefore the tag, we first need to configure the navigation menu in the Anqi CMS backend. This is the foundation for the front-end tag to work properly.

  1. Navigation Category Management: Anqi CMS allows us to create multiple navigation categories, such as "main navigation", "footer navigation", or "sidebar navigation", etc.This means we can define independent navigation structures for different areas of the website.Each navigation category has a uniquetypeIdThis ID will be called on the front endnavListUsed when labeling.

  2. Navigation link settings: Under the selected navigation category, we can add specific navigation links. Here isnavListThe embodiment of label flexibility:

    • display name: The text displayed for navigation items on the front end.
    • Subtitle/Description: Add additional information to navigation items to enrich the display effect.
    • Link Type: This is crucial! We can choose:
      • Built-in link: Such as the homepage, the homepage of specific models (articles, products), etc.
      • Category page linkDirectly associated with the existing content categories or single pages on the website. When this type is selected, the navigation item will receive aPageIdwhich will become the key for our subsequent dynamic content calls.
      • External link指向任何站内或站外的自定义URL。
    • Parent navigation: By selecting the parent navigation, we can easily build a two-level navigation menu.For example, you can set "Product Center" as the primary navigation, and the "Mobile phone" and "Computer" under it as the secondary navigation of "Product Center".

在模板中navList标签的应用:从结构到内容

一旦后台导航配置完成,我们便可以在前端模板(通常是.htmlFile) in usenavListTag to render these menus. The template syntax of Anqi CMS is similar to Django, very intuitive.

navListThe basic syntax of the tag is:{% navList navs %}...{% endnavList %}.navsis a variable name, you can customize it, it will carry the navigation data obtained from the backend, and the data will be provided in the form of an array of objects, which means we need to go throughforLoop to iterate through these navigation items.

<nav class="main-navigation">
    <ul>
        {% navList navs %}
            {%- 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 inner in item.NavList %} {# 遍历二级导航项 #}
                                <li class="{% if inner.IsCurrent %}active{% endif %}">
                                    <a href="{{ inner.Link }}">{{ inner.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

This code demonstrates a classic two-level navigation structure. Byitem.NavListWe can determine whether the current first-level navigation item contains a sub-menu and use nestedforloops to render the second-level menu.item.IsCurrentwhich can help us add the navigation item currently being visited.activeClass, implement highlighting to enhance user experience.

Dynamic Display: The Advanced Charm of Navigation Menu

navListThe essence is far more than building static second-level menus. Its real strength lies in the ability to combine with background navigation items'PageIdDynamically call and display category or document lists. This is particularly useful on websites with rich content and the need to deeply guide user browsing.

Assuming we have a primary navigation for "Product Categories" with sub-navigations such as "Mobile", "Computer", etc., which are configured in the backend as "Category Page Links", pointing to the corresponding product categories.Now, we hope that when the mouse hovers over the second-level navigation 'Phone', not only will the 'Phone' category be displayed, but also the dynamic display of several popular phone products under the category.

We can modify the template code in this way:

<nav class="main-navigation">
    <ul>
        {% navList navs with typeId=1 %} {# 假设主导航的typeId为1 #}
            {%- 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 inner in item.NavList %}
                                <li class="{% if inner.IsCurrent %}active{% endif %}">
                                    <a href="{{ inner.Link }}">{{ inner.Title }}</a>
                                    {%- if inner.PageId > 0 %} {# 判断二级导航是否关联了分类或单页 #}
                                        <div class="dynamic-content">
                                            {# 动态显示该分类下的文档列表,例如热门产品 #}
                                            {% archiveList products with type="list" categoryId=inner.PageId limit="5" order="views desc" %}
                                                {% if products %}
                                                    <h3>{{ inner.Title }}热门产品</h3>
                                                    <ul>
                                                        {% for product in products %}
                                                            <li><a href="{{ product.Link }}">{{ product.Title }}</a></li>
                                                        {% endfor %}
                                                    </ul>
                                                {% endif %}
                                            {% endarchiveList %}

                                            {# 或者,动态显示该分类的下级分类(如果存在) #}
                                            {% categoryList subCategories with parentId=inner.PageId %}
                                                {% if subCategories %}
                                                    <h3>{{ inner.Title }}子分类</h3>
                                                    <ul>
                                                        {% for subCat in subCategories %}
                                                            <li><a href="{{ subCat.Link }}">{{ subCat.Title }}</a></li>
                                                        {% endfor %}
                                                    </ul>
                                                {% endif %}
                                            {% endcategoryList %}
                                        </div>
                                    {% endif %}
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

In this code, we make use ofinner.PageIdTo determine whether the current second-level navigation item is associated with a category or a single page. IfPageIdgreater than 0, we can usearchiveListto pass the tag,categoryId=inner.PageIdDynamically pull the latest articles or popular products under this category. Similarly, it can also be usedcategoryListTags to display the sub-categories of this classification. This flexible combination makes your navigation menu more than just a collection of links, but also an entry point for content aggregation.

operational tips and practical suggestions

  • Plan firstBefore configuring navigation in the background, be sure to plan the overall structure of the website and the user's browsing path. Clear logic is the foundation of good user experience.
  • moderate hierarchy: Although it is possible to build multi-level navigation, it is recommended that the main navigation menu be kept between two to three levels, as too deep a hierarchy increases the cognitive burden on users.
  • SEO-friendlyEnsure that all navigation links are crawlable and set navigation text reasonably to include target keywords. The dynamically loaded content should also be ensured to be crawlable by search engines.
  • Responsive DesignDon't forget to optimize your navigation menu for mobile devices. On small screens, complex dropdown menus may require

Related articles

How to use the `pageDetail` tag to get detailed content and images of a single page (such as "About Us")?

In website operation, pages like "About Us" and "Contact Us" are indispensable, as they carry important information such as corporate culture, contact information, and service introduction.How to present these carefully prepared contents efficiently and beautifully on the front end of a website is a skill that every website operator needs to master.For users using AnQiCMS, the `pageDetail` tag is the key tool to achieve this goal.

2025-11-06

How to retrieve all documents under a specific Tag and implement pagination using `tagDataList` tag?

In the vast field of content operation, tags (Tags) play a crucial role.They can not only thematize and structure scattered content, but also guide users to explore deeply, improve the efficiency of content discovery, and enhance the overall user experience of the website.As an experienced website operations expert, I am well aware of the powerful capabilities of AnqiCMS (Anqi CMS) in label management and content display.

2025-11-06

How `tagList` tags display the related Tag list of the specified document?

As an experienced website operations expert, I know that how to flexibly and effectively organize and display content in a content management system is the key to improving user experience and search engine optimization (SEO).AnQiCMS (AnQi CMS) offers many powerful functions in this aspect, and the `tagList` tag is an important bridge to connect content and enhance discoverability.Today, let's delve into how to use the `tagList` tag in AnQiCMS to accurately display the associated tag list of a specified document.### Fine-grained content management

2025-11-06

How to get the link, Logo image, and document count in the `categoryList` loop?

As an experienced website operations expert, I am well aware of the importance of an efficient and flexible content management system for daily operations.AnQiCMS with its high-performance architecture based on the Go language and the friendly syntax of the Django template engine, provides us with great convenience.Today, let's explore a very practical technique in website frontend display: how to elegantly obtain the links, Logo images, and the number of documents under each category in the `categoryList` loop.

2025-11-06

How to use the `breadcrumb` tag in the AnQiCMS template to generate breadcrumb navigation?

As an experienced website operations expert, I know that a user-friendly and SEO-optimized website cannot do without a clear navigation structure, and breadcrumb navigation is the key link in this regard.It can not only help users understand their current location, improve the usability of the website, but also provide clear website structure signals for search engines.In AnQiCMS, integrating and using breadcrumb navigation is very simple and efficient, which is mainly due to its built-in `breadcrumb` tag. Today

2025-11-06

How does the `stampToDate` tag format timestamps into any custom date and time format?

## Mastering AnqiCMS `stampToDate`: Easily Customize Time Display Format The way time information is presented is crucial in the daily work of content operation.Whether it is the release date of an article, the time a product is listed, or the moment a comment is submitted, a clear and readable date and time format can greatly enhance the user experience.However, we often get a series of difficult-to-understand Unix timestamps from the database - like the number `1609470335`. Don't worry

2025-11-06

Which conditional judgment operations does the `if` logical judgment tag support in the AnQiCMS template?

As an experienced website operation expert, I am well aware that a powerful and flexible template system is crucial for the effective presentation of website content.AnQiCMS (AnQi Content Management System) takes full advantage of its high efficiency based on the Go language and the grammar features borrowed from Django template engine, providing great convenience for our content operation.In AnQiCMS template development, proficiently using logical judgment tags is the key to achieving dynamic content display and enhancing user experience.Today, let's delve into the various conditional judgment operations supported by the `if` logical judgment tag in the AnQiCMS template

2025-11-06

The `for` loop tag can iterate over arrays, but it also supports advanced usages like `reversed` or `empty`?

## The `for` loop in Anqi CMS template: Not just iteration, but advanced techniques to help you achieve twice the content operation results As a senior website operation expert, I am well aware of the importance of an efficient and flexible content management system for enterprises.AnQiCMS (AnQiCMS) leverages its high-performance architecture based on the Go language and Django template engine syntax to provide strong support for our content creation and display.In daily operations, we often need to present data collections in the form of lists on websites, at which time, the `for` loop traversal tag is undoubtedly our reliable helper

2025-11-06