How to customize the top navigation menu of a website and control its display?

Calendar 👁️ 84

The top navigation menu of the website is the first barrier for users to interact with content, and it directly affects users' understanding of the website structure and content.A well-designed, easy-to-use navigation menu can significantly enhance user experience and the professionalism of the website.AnQiCMS (AnQiCMS) offers flexible and powerful features, helping us easily customize and control the top navigation menu of the website to meet different design and operation needs.

Understanding navigation categories and structure

In Anqi CMS, the management of the navigation menu revolves around the core concept of 'navigation category'.The system provides a default "Default NavigationThis category management allows you to configure independent menus for different areas of the website, maintaining the website's layout and the uniqueness of its functions.

To create a new navigation category, just go to the "Background Settings" area of the Anqin CMS backend and find the "Website Navigation Settings" menu.Here, you can manage existing navigation categories and add new ones.Once the category is created, you can start adding specific navigation links to it.

Configure navigation links: content and display

To add links to navigation categories is a key step in customizing the menu.Each navigation link carries the responsibility of guiding users to a specific page and allows you to finely control its display style.

Core configuration items include:

  • Parent navigation:This is the basis for implementing multi-level dropdown menus.The Anqi CMS supports two-level navigation links, which means you can set a link as a main menu item and specify a submenu item for it.Select 'Top Navigation' indicates that the current link is a main menu item, and associating it with an existing menu item will make it a submenu.
  • Display name:This is the text displayed on the front page navigation link. You can name it freely, without having to match the title of the page linked, to optimize the user's visual experience and click temptation.
  • Subtitle name and navigation description:If your design requires, you can add additional subtitles or descriptions to navigation links to provide a richer content preview, which is very useful in certain showcase-style website designs.
  • Display order:By setting the number, you can control the order of the menu items. The smaller the number, the earlier the menu item is displayed. This allows you to easily adjust the position of the menu items without having to recreate them.

Link Type:

AnQi CMS offers three flexible link types, ensuring you can point to any location within or outside the website:

  1. Built-in links:Including the homepage of the website, homepages of different content models (such as article model homepage, product model homepage), and other commonly used links.Select these built-in options to ensure the stability and accuracy of the link.
  2. Category page links:Allow you to directly link the navigation to the existing category page or independent page on the website.When you want to highlight a product category or an independent page like 'About Us' in navigation, this option is very useful.
  3. External links:Provided with the greatest flexibility, you can enter any valid URL address, whether it is a custom link to another page within the site or a link to an external website, it can be easily integrated into your navigation menu.

Control the display of the navigation menu in the template

After configuring the navigation links, we need to call and display these menus in the website's front-end template. Anqi CMS is usednavListTag to implement this feature.

Assuming you have created a category for top navigation with the category ID of1. You can use the following code in the template file to display a two-level menu:

{% navList navs with typeId=1 %} {# 假设1是您的顶部导航类别ID #}
    <nav class="main-navigation">
        <ul>
            {% for item in navs %}
                <li class="{% if item.IsCurrent %}active{% endif %}"> {# 使用IsCurrent判断是否为当前页面,添加active样式 #}
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                    {% if item.NavList %} {# 如果有子导航,则渲染第二级菜单 #}
                        <ul class="sub-menu">
                            {% for subItem in item.NavList %}
                                <li class="{% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
    </nav>
{% endnavList %}

In this template code:

  • {% navList navs with typeId=1 %}Specified the navigation category to be called (here is the category with ID 1).
  • {% for item in navs %}Loop through the main menu items.
  • {{ item.Link }}and{{ item.Title }}Output the link address and display name of the menu items separately.
  • {% if item.IsCurrent %}Used to determine if the current menu item matches the page the user is visiting, usually used to highlight the navigation item currently in place.
  • {% if item.NavList %}Check if there is a submenu under the current main menu item. If there is, go through again.{% for subItem in item.NavList %}Loop to render the second-level submenu.

Through this mechanism, Anqi CMS perfectly combines the flexibility of backend configuration with the display control of front-end templates, allowing you to freely customize the style and function of the navigation menu according to the design style and interaction requirements of the website.

Frequently Asked Questions (FAQ)

Q1: Why did I set the navigation link but it did not display on the website front end?A1: Firstly, please confirm that you have added the navigation link to the correct 'Navigation Category' in the background 'Website Navigation Settings', and that the category ID is passed through the templatetypeIdThe parameter was called correctly.Next, check whether the navigation links you added include all the necessary fields (such as display name, link address), and whether the display order is reasonable.base.htmlor a specific navigation block file was used correctlynavListthe tag to render the navigation category

Q2: Can AnQi CMS support creating a three-level navigation menu?A2: The Anqi CMS backend management interface supports default two-level structure for navigation links (i.e., main menu items and their sub-menu items). If you need to implement deeper three-level or multi-level navigation, you need to manually adjust the template code by judgment.subItem.NavList(That is, the existence of the submenu item of the second-level menu) whether to render extra, but this usually requires more complex CSS and JavaScript support, and may affect the user experience, it is recommended to consider carefully.

Q3: How to make a navigation link open in a new window instead of the current page when clicked?A3: The Anqi CMS backend currently does not have an option to set navigation links to open in a new window. You need to manually modify it in the template file.<a>Add tagtarget="_blank"Implement a property. For example, change<a>the tag to<a href="{{ item.Link }}" target="_blank">{{ item.Title }}</a>, so that clicking the link will open in a new window.

Related articles

How does AnQiCMS provide visitors with language switching options for content display?

In today's globally interconnected digital age, websites have become a basic need to provide content for users of different languages.No matter whether your business is aimed at the global market or simply wants to cover users in different dialect regions within the country, a website that supports multilingual switching can significantly improve user experience and brand influence.AnQiCMS (AnQiCMS) fully understands this need and provides an efficient and flexible solution to help your website seamlessly switch between multilingual content.

2025-11-08

How to aggregate and display a list of selected articles under multiple categories on a single page?

In website operation, we often encounter such needs: on the homepage or a special topic page, we can display selected articles from different categories, which can enrich the page content and guide users to discover more interesting information.AnQiCMS provides very flexible and powerful features, allowing us to easily achieve this goal without complex programming knowledge.

2025-11-08

How to display the links to the previous and next articles at the bottom of the article detail page?

In website content operation, improving user reading experience is a key link.After a reader has finished browsing an excellent article, if they can immediately see a link to the next related or sequential article, it will undoubtedly greatly increase the likelihood that they will continue to stay on the website.This design not only optimizes the user experience, helps guide users to delve deeper into the website's content, but also effectively reduces the bounce rate and enhances the website's SEO performance, allowing search engines to better understand the structure of your website's content.

2025-11-08

How to filter and display related article lists on the front page according to the specified category ID?

In Anqi CMS, it is actually very simple to filter and display a list of related articles on the front page according to the category ID!The AnQi CMS, with its efficient and flexible features, makes content management and display easy.No matter if you are running a corporate website, an industry information station, or a personal blog, you may encounter the need to display a list of articles according to a specific category.For example, display articles from a certain "Hot Recommendation" category on the homepage, or showcase specific "Product Cases" on a special topic page.Today, let's talk about how to accurately implement this function in the Anqi CMS front-end template.###

2025-11-08

How to use the `replace` filter for string keyword replacement in AnQiCMS templates?

When operating content on AnQiCMS, we often encounter situations where we need to dynamically process the text output from the website template, such as uniformly modifying a brand name, correcting typographical errors, or adding prefixes/suffixes to specific keywords.At this time, the `replace` filter has become a powerful tool for us to meet these needs.It can help you flexibly adjust the string displayed on the page without modifying the original content data.### `replace` filter

2025-11-08

What is the core role of the `replace` filter in AnQiCMS website content display?

In AnQiCMS (AnQiCMS) website content display, the `replace` filter plays a core and practical role, giving content operators the ability to flexibly control the front-end display of content without modifying the original data.In simple terms, this filter helps us replace a specific string in the content with another, thus achieving various refined display adjustments.This function's core value lies in its 'non-intrusiveness' and 'high efficiency'.

2025-11-08

How to accurately replace a specific word in the title or description of AnQiCMS articles?

In website operation, we often encounter the need to uniformly modify the titles or descriptions of a large number of articles.Whether it is a brand renaming, product line adjustment, or keyword strategy update for optimizing search engines (SEO), manually modifying one by one is undoubtedly a time-consuming and labor-intensive task that is prone to errors.Luckily, AnQiCMS has fully considered these operational needs and provided a set of efficient and accurate solutions.

2025-11-08

Can the AnQiCMS `replace` filter achieve dynamic replacement of variable values?

AnQiCMS is an efficient and feature-rich enterprise-level content management system that provides great flexibility to content operators.In the daily content display and processing, we often encounter the need to replace specific text, such as unify brand words, correct misspellings in the content, or dynamically adjust the display content under specific conditions.At this time, the template filter provided by AnQiCMS is particularly important.

2025-11-08