How to implement the `navList` tag for flexible display of top, bottom, or sidebar navigation menus on a website?

Calendar 👁️ 76

The website navigation is a guide for users to explore the content of the website, and it is also an important clue for search engines to understand the structure of the website.A well-designed, flexible navigation system that can greatly enhance user experience and website SEO performance.navListTag is indeed such a core tool, which gives us great freedom, allowing us to easily build and manage navigation menus at various positions such as the top, bottom, and sidebar of the website.

Then,navListHow does the tag actually implement this flexible and variable navigation display? Let's delve into its usage and the mechanisms behind it.

UnderstandingnavListcore mechanism

In AnQiCMS, the navigation menu is not simply hardcoded in the template.On the contrary, all navigation data is concentrated in the "Website Navigation Settings" on the backend.Here, we can create different navigation categories, such as main navigation, footer navigation, or sidebar navigation, each category has its own menu items.navListThe role of tags is to extract the configured data from the background in a structured way for use in the front-end template.

Its basic usage is very intuitive, we usually call it like this in the template:

{% navList navs %}
    {# 在这里通过循环遍历导航项 #}
{% endnavList %}

here,navsIt is a variable name specified for the navigation list obtained, you can name it according to your preference.navListThe label will retrieve all menu items associated with a specific navigation category from the background and provide them asnavsvariables to us.

Build your first navigation menu

Assuming we need to display a main navigation menu at the top of the website.In the "Website Navigation SettingsnavListto display them:

<nav class="main-navigation">
    <ul>
        {% navList navs with typeId=1 %} {# 假设“默认导航”的ID是1 #}
            {%- for item in navs %}
                <li class="{% if item.IsCurrent %}active{% endif %}">
                    <a href="{{ item.Link }}">{{item.Title}}</a>
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

This code first goes throughtypeId=1Specify the navigation category with ID 1. Then, it will traversenavseach navigation item in the list (item)). For each navigation item, we can access itsTitle(display name) andLink(Link address).item.IsCurrentThis boolean value is very practical, it will automatically judge whether the current page being visited matches the navigation item, if it matches, it will returnTrueWe can use this property to add the 'active' class to the navigation items of the current page to highlight them.

The intricacies of implementing multi-level navigation.

AnQiCMS'navListTags do not only support first-level navigation, they can also easily implement multi-level drop-down menus. Each navigation itemitemmay contain oneNavListThe attribute represents the sub-navigation menu. We can render these sub-menus through nestedforcyclic loops:

<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 %} {# 判断是否存在子导航 #}
                        <dl class="sub-menu">
                            {%- 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 %}
        {% endnavList %}
    </ul>
</nav>

By using such a nested structure, no matter how many levels of sub-menus are set in the background (AnQiCMS supports two levels by default), the front-end can present them flexibly. In addition, we can also make use ofitem.SubTitleanditem.DescriptionThese fields add more auxiliary information to the navigation items, such as displaying a brief introduction below the title to make the menu more vivid.

Seamlessly connect navigation with dynamic content.

navListThe power of tags is not just limited to static links.It can deeply integrate with AnQiCMS content management system to achieve dynamic content loading of navigation menus.PageIdProperty. When a navigation link is set in the background to point to a category or a single page,PageIdit will store the ID of the category or page.

For example, we can dynamically display the sub-categories under a main navigation item named 'Product', and even directly list the popular products under this category.

Scenario one: Display category list under navigation

If you want to display all product subcategories under your main navigation item 'Products', you can handle it like this:

<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 %} {# 检查子导航项是否关联了页面/分类ID #}
                    {% categoryList categories with parentId=inner.PageId %} {# 获取该ID下的子分类 #}
                    {% if categories %}
                    <ul>
                        {% for subCategory in categories %}
                        <li>
                            <a href="{{ subCategory.Link }}">{{subCategory.Title}}</a>
                        </li>
                        {% endfor %}
                    </ul>
                    {% endif %}
                    {% endcategoryList %}
                {% endif %}
            </li>
            {% endfor %}
        </ul>
        {% endif %}
    </li>
    {% endfor %}
</ul>

Here, we utilizedinner.PageIdascategoryListlabel'sparentIdParameters, thus dynamically acquiring and displaying the sub-categories associated with the secondary navigation items. This method is very suitable for building complex product category navigation.

Scenario two: Display a list of specific documents (such as products or articles) under navigation

If you want to list several popular articles directly below a navigation item (such as "Popular Articles"), you can also make use ofPageIdCombinearchiveListTags:

<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>
                {% archiveList products with type="list" categoryId=inner.PageId limit="8" %} {# 获取该ID下最新的8篇文档 #}
                {% if products %}
                <ul class="nav-menu-child-child">
                    {% for productItem in products %}
                    <li><a href="{{productItem.Link}}">{{productItem.Title}}</a></li>
                    {% endfor %}
                </ul>
                {% endif %}
                {% endarchiveList %}
            </li>
            {% endfor %}
        </ul>
        {% endif %}
    </li>
    {% endfor %}
</ul>

In this example,archiveListTag throughcategoryId=inner.PageIdThe parameter retrieves the latest 8 documents associated with the secondary navigation item category (here assumed to be products) and directly displays these product links in the menu.This dynamic integration greatly enhances the usability and content depth of the navigation menu.

skills and considerations in practical applications

in actual usenavListWhen labeling, there are some practical tips and things to pay attention to:

  1. Backend navigation category managementIn the "Background Settings" -> "Navigation Settings", you can click on "Navigation Category Management" to create and manage multiple navigation categories. Each category will have a uniquetypeId, you can in thenavListUsed in tagstypeIdParameters to accurately call navigation to the required location, for exampletypeId=2Used for footer navigation,typeId=3Used for sidebar navigation.
  2. siteIdUsed for multi-siteIf you are using the multi-site feature of AnQiCMS and want to call navigation data from other sites, you cansiteIdThe parameter specifies the target site ID to achieve flexible cross-site navigation content calling.
  3. Optimization of template structure: In order to keep the template code neat.

Related articles

How to use the `tagDetail` and `tagDataList` tags to display information about a specific tab page and its associated documents?

AnQiCMS (AnQiCMS) is a flexible and efficient content management tool trusted by many operators.It is crucial to effectively present content classification and organization methods when building a functional and user-friendly website.Especially for the need to associate different content through "tags", mastering the use of the `tagDetail` and `tagDataList` template tags can make your website's tag page not only beautiful but also informative, greatly enhancing user experience and search engine optimization (SEO) effects.

2025-11-08

What are the applications of the `pageDetail` and `pageList` tags in displaying single-page content and list presentation?

When using AnQiCMS to build a website, the display of single-page content and page lists is an indispensable part.Whether it is an independent content page like "About Us" or a series of links in the website footer navigation, they all need flexible and efficient ways to manage and present.In AnQiCMS, the `pageDetail` and `pageList` tags are powerful tools designed to meet these needs.They each focus on different application scenarios and yet complement each other

2025-11-08

How to use the `categoryList` tag to build a multi-level category navigation and control its display level?

The website's navigation system is like a map, guiding visitors smoothly to their destination.A well-organized, layered classification navigation that can significantly improve the user's browsing experience and also help search engines understand and index your website content more efficiently.In AnQi CMS, the `categoryList` tag is the tool to build a high-efficiency and flexible category navigation system.With it, you can easily display the website's category structure, even fine-tune the display level of each category.### `categoryList` Label Overview

2025-11-08

How does the `categoryDetail` tag help us retrieve and display detailed information for a specific category?

AnQiCMS (AnQiCMS) provides powerful and flexible tools for website content management, among which the `categoryDetail` tag plays a very important role in building a rich and structured website.It can help us accurately obtain and display detailed information about specific categories, whether it is used for the header introduction on the category list page or to display more content about the category in the article detail page, it is very convenient.### `categoryDetail` tag basic usage In simple terms

2025-11-08

How to build a clear breadcrumb navigation through `breadcrumb` tags to enhance users' sense of positioning on the website?

In website operation, how to keep visitors from getting lost in the vast content while browsing, and maintain a clear sense of orientation, is a crucial issue.Imagine if a user delves into a page on a website and is unclear about where they came from or their level, they are likely to feel confused and even choose to leave.At this time, a well-designed and functional breadcrumb navigation can play a key role, it is like a 'road sign' in the digital world, providing users with a clear return path.AnQiCMS (AnQiCMS) is deeply skilled in content management and user experience

2025-11-08

How is the `bannerList` tag used to fetch and display the carousel of the website homepage or a specific group?

When building modern websites, the banner carousel is a commonly used element to enhance visual appeal and convey important information.They are usually located in prominent positions on websites, such as the top of the homepage, to display the latest activities, featured products, or important announcements.In AnQiCMS (AnQiCMS), managing and displaying these carousel images becomes very convenient, mainly due to its powerful template tag system, especially the `bannerList` tag.`bannerList`

2025-11-08

What global website information and contact details can the `system` tag and `contact` tag retrieve and display?

In the daily operation of AnQiCMS, the global information and contact information of the website are highly concerned by users and frequently change.How to efficiently and uniformly manage and display this information is an important standard for measuring the flexibility of a content management system.AnQiCMS provides an extremely convenient solution for calling website content and contact information through its unique template tag system, especially the core tags `system` and `contact`.

2025-11-08

How to dynamically generate and display SEO titles, keywords, and descriptions for `tdk` tags on different pages?

In website operation, the title (Title), keywords (Keywords), and description (Description), known as TDK, are indispensable core elements of search engine optimization (SEO).They not only directly affect the display of the website on the search engine results page (SERP), but also determine whether users click to enter your website.

2025-11-08