How to use the `navList` tag to implement a dropdown menu effect in AnQi CMS navigation?

Calendar 👁️ 52

Building an efficient and user-friendly website navigation in Anqi CMS is a key factor in improving user experience.Especially for content-rich websites, dropdown menus can help users quickly locate the information they need while keeping the page neat.Strong and powerful provided by AnQi CMSnavListTags, allowing website operators to flexibly implement this effect in templates.

Understanding the navigation management mechanism of Anqi CMS.

Before delving deepernavListBefore the label, we first need to understand how Anqi CMS manages website navigation.In the AnQi CMS backend, the navigation menu configuration is located under the "Navigation Settings" module in the "Backend Settings".This can not only set the default top navigation, but also add custom navigation to other locations according to the specific needs of the website, such as footer navigation or sidebar navigation.Each navigation category can include multi-level navigation links, the current system supports up to two-level dropdown menus, which lays a foundation for achieving the standard two-level dropdown menu effect.

navListBasic application of tags.

navListThe tag is a core tool in the Anqi CMS template used to obtain the page navigation list. Its basic usage is{% navList navs %}...{% endnavList %}. Here,navsIs a custom variable name, you can name it according to your habits, but please make sure to use the same variable name in the subsequent loops.

navListThe tag supports several key parameters to accurately control the navigation data obtained:

  • typeId: This is the ID of the background navigation category. Anqi CMS allows you to create multiple navigation categories (such as “main navigation”, “footer navigation”, etc.), each of which has a unique ID.Through specificationtypeIdYou can optionally call the navigation menu of a specific category. If not specifiedtypeIdThe system will usually default to the navigation category with ID 1.
  • siteId: This parameter is used in multi-site management scenarios. If you have created multiple sites in the background and want to call the navigation data of other sites, you can specifysiteIdTo implement. For single-site settings, this parameter is usually not required.

navListThrough the tag internal.forLoop through the navigation items. Each navigation item (usually nameditemAll of them include the following important fields, which are crucial for building drop-down menus:

  • Title: The text title displayed for navigation items.
  • Link: The URL link of the navigation item.
  • IsCurrent: A boolean value indicating whether the current navigation item is the navigation item on the current page, commonly used for addingactiveto highlight the class.
  • NavList: This is a very critical field. If the current navigation item has child navigation,NavListIt will be an array containing these sub-navigation items, with the same structure as the parent navigation item. It is the existence of this field that makes the implementation of multi-level dropdown menus possible.

Build a basic two-level dropdown menu

To implement a basic two-level dropdown menu, we need to nest it in the template usingforLoops and combineitem.NavListTo determine if a submenu exists.

Here is a typical code structure that shows how to usenavListBuild an HTML structure with two-level dropdown menus:

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

In this example, the outerforLoop through the top-level navigation items. Inside each top-level navigation item, through{% if item.NavList %}Determine whether the item has a sub-navigation. If it exists, it will render aulelement as a dropdown menu, and use the innerforLoop throughitem.NavListof the child navigation item.IsCurrentfield is used to add to the currently active menu item.activeclass for easy styling highlighting with CSS.

Please note that the above code mainly focuses on the HTML structure. The actual dropdown menu animations (such as displaying on hover and switching on click) and visual styles (such as background color, font, borders) all need to be implemented through custom CSS and JavaScript.

Advanced Application: Nested categories and documents in dropdown menus.

navListThe power goes beyond simply displaying simple links. As a website operator, we often need to display richer content based on navigation items, such as a list of subcategories under a category, even the latest documents under that category.Our AnqiCMS allows us to use other tags likecategoryListandarchiveListnested innavListIn the loop, thus achieving more dynamic and functional dropdown menus.

Consider a scenario, you want to display product categories under the main navigation "Products" menu, and also directly show some products under each category. This can be achieved in the following way:

<nav>
    <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>
                    <a href="{{ inner.Link }}">{{inner.Title}}</a>
                    {% if inner.PageId > 0 %} {# 假设 PageId 存储了对应的分类ID #}
                        {% archiveList products with type="list" categoryId=inner.PageId limit="8" %} {# 调用该分类下的产品列表 #}
                        {% if products %}
                        <ul class="sub-sub-menu"> {# 这是一个三级菜单,显示产品 #}
                            {% 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>
</nav>

In the above example, we assume that the second-level navigation item'sPageIdfield stores the corresponding category ID. By{% archiveList products with type="list" categoryId=inner.PageId limit="8" %}We can dynamically retrieve and display 8 product documents under this category, thus presenting more rich content in the dropdown menu.

Another common requirement is to display nested subcategories in the dropdown menu.For example, the main navigation "About Us" includes "Company Introduction" and "Team Style", and the "Company Introduction" may also include "Development History".This can also be donenavListCombinecategoryListImplementation:

<nav>
    <ul>
        {% navList navs with 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>
                    <a href="{{ inner.Link }}">{{inner.Title}}</a>
                    {% if inner.PageId > 0 %} {# 假设 PageId 存储了对应的分类ID #}
                        {% categoryList categories with parentId=inner.PageId %} {# 获取该分类下的子分类 #}
                        {% if categories %}
                        <ul class="sub-sub-menu"> {# 这是三级菜单,显示子分类 #}
                            {% 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>
</nav>

Through these flexible nested combinations, Anqi CMS'snavListtags for website navigation design provide great freedom and extensibility.

Style and user experience suggestions

When implementing a dropdown menu, the HTML structure is just the foundation. To provide a good user experience, it is necessary to implement appropriate styles and interactions through CSS:

  • Hide and show: Using CSS'sdisplay: none;anddisplay: block;oropacityandvisibilityproperty, combined:hoveror JavaScript to control the display and hide of the dropdown menu.
  • transition animationAddtransitionproperty can make the menu expand and contract more smoothly.
  • Responsive Design: Make sure that dropdown menus are presented in a user-friendly manner on different devices (especially mobile devices), such as converting to an accordion menu or a sliding menu.
  • Accessibility: Consider adding WAI-ARIA attributes to dropdown menus to ensure screen reader users can understand and operate navigation.

By carefully designed navigation structure and style, we can make use of Anqie CMS'snavListtags, providing users with an intuitive and efficient website browsing experience.

Frequently Asked Questions

Q1: Why is the dropdown menu I wrote according to the example code not displayed?

A1: If the drop-down menu does not display, first check your backend navigation settings. Make sure you have added sub-navigation for the relevant navigation items, andtypeIdThe parameter correctly points to the navigation category containing these dropdown items.In addition, HTML structure and CSS style are also crucial.Make sure your CSS rules correctly hide the submenu (for exampledisplay: none;),and it has corresponding display rules when hovering over the parent menu, for exampledisplay: block;)。Finally, check the browser console for any JavaScript errors that might prevent the menu from interacting normally.

Q2: Anqi CMS'snavListDoes the tag support three or more levels of dropdown menus?

A2:navListThe tag itself directly supports two levels of navigation in the returned data structure (i.e.itemanditem.NavList)。If you need to implement a third-level or deeper dropdown menu, you need to check each item in theitem.NavListloop to see if it has its ownNavList, and perform deeper nesting. For example,inner.NavListIt can be used for the third-level menu. However, from the perspective of user experience, too deep navigation levels often confuse users, and it is usually recommended to control the navigation levels within two to three levels.

Q3: How to ensure that my dropdown menu also works on mobile devices?

A3: Pure CSS:hoverThe dropdown menu usually performs poorly on touch screen devices. To achieve a good mobile experience, you need to adopt responsive design strategies.This usually involves using media queries (Media Queries) to modify navigation styles on small screen sizes, such as converting traditional horizontal drop-down menus into vertical accordion menus, drawer menus (Hamburger Menu), or bottom navigation bars.These usually need to be combined with JavaScript to implement the logic for clicking to switch menus, rather than relying solely on hover events.You can use jQuery or other JavaScript frameworks to assist in implementing these interactive effects.

Related articles

How to call custom navigation categories in the AnQi CMS template using the `navList` tag?

As a website operator who deeply understands the operation of AnQi CMS, I know that a clear and efficient navigation system is crucial for user experience and website SEO.In Anqi CMS, the `navList` tag is the core tool for building flexible and versatile navigation menus.It can not only help you display the standard top navigation, but also allow you to easily call and customize various navigation categories to meet the diverse layout needs of the website, such as footer navigation, sidebar navigation, and even context navigation for specific pages.

2025-11-06

How many levels of sub-menus does the Anqi CMS navigation list support?

As an experienced website operator who has a deep understanding and rich experience with AnQiCMS, I know the importance of the navigation system for user experience and website structure.Under the AnQiCMS framework, we can build clear and efficient website navigation to meet various operational needs.About the level of sub-menu support for the AnQi CMS navigation list, I can provide a detailed explanation.

2025-11-06

How to adjust the display order of Anqi CMS navigation links?

HelloAs an experienced CMS website operation manager, I fully understand the importance of website navigation for user experience and information architecture.Clear and logical navigation not only helps users quickly find the content they need, but also improves the overall SEO performance of the website.Next, I will give you a detailed introduction on how to adjust the display order of navigation links in AnQiCMS.In AnQiCMS, the display order of navigation links is mainly adjusted through the "Navigation Settings" function in the backend.

2025-11-06

Can the AnQi CMS navigation link point to an external website address?

As an experienced CMS website operation personnel of a security company, I am very familiar with the importance of navigation links in content management systems and their role in the overall strategy of the website.About whether the navigation link of Anqi CMS can point to external website addresses, I can clearly tell you that: Anqi CMS provides flexible support for external links, which is of great strategic significance in actual operation.The Anqi CMS fully considered the flexibility and diversity of website operations from the beginning of its design.When building a website's navigation system, we often need to guide users to access different pages within the site

2025-11-06

How can you make the AnQi CMS navigation link automatically display products or articles under the category?

In the daily operation of Anqi CMS, how to make the navigation links automatically display the products or articles under their categories is an important aspect for improving user experience and content discoverability.By carefully configuring the background navigation settings and combining with the powerful template tag function of AnQiCMS, we can easily achieve this goal, presenting the website content in a more intelligent and dynamic way to visitors.First, the website navigation settings are basic.

2025-11-06

What will happen if the custom template pointed to by the AnQi CMS navigation link does not exist?

As a website operator who deeply understands the operation of Anqi CMS, I am well aware of the importance of content presentation and user experience.In Anqi CMS, navigation links are the key paths for users to explore the website, and the templates behind them are the foundation for determining whether the content can be displayed correctly.When a navigation link points to a custom template that does not exist, it is not just a simple file missing, but also a major challenge to user experience and website professionalism.

2025-11-06

Under multi-site management, is the Anqi CMS website navigation setting independent?

**AnQiCMS multi-site management, independent analysis of website navigation settings** In the multi-site management architecture of AnQi Content Management System (AnQiCMS), the website navigation settings are highly independent.This independence is a core feature established in the initial design of AnQiCMS to meet the needs of enterprises and operators who have multiple brands, sub-sites, or require content branch management.

2025-11-06

How does the Anqi CMS navigation setting affect the website's SEO?

As an experienced website operator who has been deeply involved in AnQiCMS for many years, I know that navigation settings are crucial for the SEO of a website.A well-planned and configured website navigation can not only effectively guide users, but also profoundly affect the search engine's crawling, understanding, and ranking of the website's content.Anqi CMS was designed with SEO-friendliness in mind, its navigation settings function provides a variety of options, allowing operators to flexibly build a strong SEO foundation for the website.

2025-11-06