How to dynamically generate and display the top or bottom navigation menu of a website?

Calendar 👁️ 70

In website operation, the top and bottom navigation menus play a crucial role, not only as guides for users to explore the content of the website, but also as key to search engines understanding the structure of the website.A well-designed, dynamically generated navigation menu that can greatly enhance user experience and website maintainability.AnQiCMS provides a user-friendly and powerful set of features to help you achieve this goal.

Background configuration: Bring your menu to life

To dynamically generate and display the navigation menu in Anqi CMS, you first need to configure the menu content in the background.This is like drawing a map for your website, planning various destinations.

You can find it in the background: Backend settingsModule, click to enter and selectWebsite navigation settings. This is the centralized management area for all navigation menus.

Firstly, you can define differentnavigation category. The system usually provides a default navigation, but if your website needs multiple independent navigation areas, such as one at the top, one at the bottom, or different menus in the sidebar, you can create new navigation categories here.For example, you can create a new category named 'Footer Navigation' specifically for the website footer.This way, different navigation areas can be independently managed without interference.

Next isNavigation link settingsThis is the section for filling menu content. When adding new navigation links, you will see the following important configuration items:

  • Parent navigationThis option allows you to easily build a multi-level dropdown menu.If you want the current link to be a top-level menu item, select "Top Navigation";If it should be a submenu of an existing menu item, select the corresponding parent menu.AnQi CMS currently supports two-level navigation, which is enough to meet the needs of most websites.
  • display nameThis is the text displayed on the front page navigation link. You can set it flexibly and it does not necessarily have to match the name of the content pointed to by the link.
  • Subtitle name and navigation descriptionThese fields provide additional display space. If your navigation needs richer text information, such as English subtitles or brief descriptions, you can enter them here for easy front-end template calls.
  • Link TypeThis is the core definition of where the navigation link points. Anqi CMS provides multiple options:
    • Built-in link: Includes the home page, content model home pages (such as article model home pages, product model home pages, etc.), these are the commonly used links preset by the system.
    • Category page link: You can directly select any created article category, product category, or single page as a navigation link.
    • External linkIf you need to link to external resources or other custom URLs, you can select this option and enter the complete link address.
  • Display order: By adjusting the size of the number, you can control the order of the menu items, with smaller numbers appearing earlier.

With these flexible configurations, you can intuitively build various complex navigation menus in the background without touching any code.

Front-end template: Turn configurations into a visual menu

After you configure the navigation content in the background, the next step is to display this data on the website's frontend page.The Anqi CMS template system adopts a syntax similar to the Django template engine, which is concise and efficient, making technical information easy to understand and apply.

In the template file, we mainly usenavListthis tag to get navigation data. This tag's function is to dynamically extract the navigation list you have configured from the background database.

The navigation menu code is usually placed in a common template file (such asbase.htmlorpartial/header.html/partial/footer.html), and then referenced by{% include %}tags on various pages.

A basic single-level navigation menu template code is roughly as follows:

{# 假设这是您的顶部导航区域 #}
<nav class="main-navigation">
    <ul>
        {% navList navs with typeId=1 %} {# typeId=1 通常指代默认导航类别 #}
            {% for item in navs %}
                <li {% if item.IsCurrent %}class="active"{% endif %}>
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

This code first uses{% navList navs with typeId=1 %}tags to retrievetypeIdAssign all navigation data for 1 (i.e., the default navigation category) tonavsvariable. Then, by{% for item in navs %}Loop through each navigation item. EachitemIt includes such asTitle(Display name),Link(link address),IsCurrentProperties such as (whether it is a link on the current page), you can call them as needed.{% if item.IsCurrent %}This code is very useful, it can help you add highlight styles to the navigation menu items corresponding to the current page, enhancing the user experience.

If your navigation menu includes a secondary dropdown menu, the code will be slightly more complex, but the core logic is still nested loops:

{# 包含二级下拉菜单的顶部导航 #}
<nav class="main-navigation">
    <ul>
        {% navList navs with typeId=1 %}
            {% for item in navs %}
                <li {% if item.IsCurrent %}class="active"{% endif %}>
                    <a href="{{ item.Link }}">
                        {{ item.Title }}
                        {% if item.NavList %}<i class="arrow-down"></i>{% endif %} {# 如果有子菜单,显示一个小图标 #}
                    </a>
                    {% if item.NavList %} {# 判断是否有下级导航 #}
                        <ul class="submenu">
                            {% for sub_item in item.NavList %}
                                <li {% if sub_item.IsCurrent %}class="active"{% endif %}>
                                    <a href="{{ sub_item.Link }}">{{ sub_item.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

Here, we use{% if item.NavList %}To determine if the current main menu item has a submenu. If it does, use one more time.{% for sub_item in item.NavList %}Loop to render the submenu items,sub_itemSimilarly, have.Title/Link/IsCurrentsuch properties.

Through such a template structure, any modification you make in the background configuration will be immediately reflected on the website front-end, realizing the true meaning of dynamic menus.

Practical Tips and **Practice**

  • SEO friendlyEnsure you use meaningful text as the 'Display Name' when setting navigation links, as this helps search engines understand your website content. For links to external websites, you can manually add them in the front-end code.rel="nofollow"Property, prevent unnecessary weight loss, or select when configuring links in the backgroundNofollow.
  • Enhancing user experience:
    • Clear hierarchyAvoid deep navigation levels, usually two to three levels are enough for users to quickly find the information they need.
    • Responsive DesignEnsure that your navigation menu displays and operates well on different devices (such as mobile phones, tablets).The Anqi CMS supports adaptive, code adaptation, and PC+mobile independent site mode, providing a foundation for responsive navigation.
    • Highlight the current pageUtilizeitem.IsCurrentThe attribute adds a prominent style to the navigation items on the user's current page, helping users maintain a sense of direction.
  • Maintain convenience.All navigation content is managed in the background, no need to modify the template code, which greatly reduces the maintenance cost and error rate of daily operations.
  • Multi-site applicabilityThe AnQi CMS multi-site management feature allows each site to have its own independent navigation configuration, even if you are managing multiple websites, you can maintain the flexibility and customization of each site.

AnQi CMS provides a user-friendly backend management interface and flexible template tags, making it extremely simple and efficient to dynamically generate and display the top or bottom navigation menu of a website.Whether it is an official website of a small and medium-sized enterprise, a personal blog, or a content marketing platform, you can easily handle it, making the website menu a powerful helper to guide users to explore in depth.


Frequently Asked Questions (FAQ)

Q1: Why did the front page not update after I modified the navigation settings on the backend?A1: AnQi CMS usually enables caching to enhance website performance.If you have modified the navigation settings in the background but they do not take effect on the front end, you can try clearing the system cache.In the background management interface, there is usually an 'Update Cache' feature entry, click on it, wait for a few seconds, and then refresh the front page to see the update.

Q2: How to set different content for different navigation areas (such as top menu and bottom menu)?A2: In the Anqi CMS backend "Website Navigation Settings", you can create multiple "Navigation Categories".For example, you can create a navigation bar named "Top Main Navigation", and then create a navigation bar named "Footer Auxiliary Navigation".call in the templatenavListwhen using tags, bytypeIdThe parameter specifies the calling of different navigation categories, for example{% navList topNavs with typeId=1 %}(Assuming 1 is the top navigation ID) and{% navList footerNavs with typeId=2 %}(Assuming 2 is the footer navigation ID).

Q3: Can the navigation menu link to external websites or my custom specific URL?A3: Of course, you can. When adding or editing navigation links in the "Website Navigation Settings" backend, set the "Link Type" to "External Link", and then directly enter the external URL or custom path you want to point to in the "Link Address" field.

Related articles

How to generate and display multi-level breadcrumb navigation in AnQi CMS?

In website content operation, a clear navigation path is crucial for user experience and search engine optimization.A good breadcrumb navigation can help users quickly understand the current page's position in the website structure and make it convenient for them to backtrack to the previous level or higher-level pages.AnQiCMS (AnQiCMS) fully understands this, therefore it provides a powerful and easy-to-use breadcrumb navigation feature that allows website administrators to easily generate and display multi-level breadcrumbs.The core of implementing breadcrumb navigation in Anqi CMS lies in its built-in `breadcrumb` tag

2025-11-07

How to configure and display SEO title, keywords, and description (TDK) on the website homepage?

In website operation, the search engine optimization (SEO) of the homepage is crucial.A well-configured SEO title, keywords, and description (TDK) can significantly improve the visibility of a website in search engine results pages (SERP), attracting more potential visitors.AnQiCMS (AnQiCMS) is a system designed for SEO-friendliness, providing an intuitive and convenient way to manage key information.This article will guide you to understand how to configure and display SEO title, keywords, and description on the homepage of your AnQiCMS website.--- ### One

2025-11-07

How to retrieve and display the contact information set in the background (such as phone number, email, WeChat)?

In website operation, clearly displaying contact information is crucial for enhancing user trust and promoting interaction.Whether it is to consult products, seek support, or engage in business cooperation, convenient contact channels can greatly improve conversion rates.AnQiCMS (AnQiCMS) understands this and provides flexible and powerful features, allowing you to easily obtain and display various contact information in website templates.Next, let's take a look at how to display the contact information, such as phone, email, WeChat, etc., set in the background of Anqi CMS, naturally and smoothly on your website

2025-11-07

How to configure and display the website name and copyright information in AnQi CMS?

A website's name and copyright information is an important embodiment of its brand image and legal attribution.In AnQiCMS (AnQiCMS), these core elements are configured and displayed flexibly and intuitively, which can help website operators manage easily, ensuring the professionalism and compliance of the website. ### Configure website basic information In AnQiCMS, the basic configurations such as website name, copyright information, and so on are mainly concentrated in the "Global Function Settings" area of the background.Here is like the 'control center' of your website, centrally managing many core parameters.1. **Website Name**

2025-11-07

How to retrieve and display a list of articles or products in a loop?

Build an energetic website in AnQiCMS, the display of the content list is an indispensable part.Whether it is to display the latest released articles, hot products, or content under specific categories, AnQiCMS' powerful template engine can help us easily achieve it.This article will delve into how to retrieve and loop through lists of articles or products in AnQiCMS, helping you flexibly build diverse content display pages.## Understanding AnQiCMS content list mechanism AnQiCMS uses a template engine syntax similar to Django

2025-11-07

How to display a list of articles or products under a specific category in AnQiCMS?

In AnQiCMS, displaying a list of articles or products under a specific category is a common need in website content management.To build subpages under the navigation menu or to showcase selected content from different modules on the homepage, AnQiCMS offers a flexible and powerful way to achieve this goal.Understanding the content organization logic and the use of template tags will allow you to easily present the required content on the website.### Understanding AnQiCMS content model and categories Firstly, the organization of AnQiCMS content is based on "content model" and "categories"

2025-11-07

How to display document recommendation attributes (such as headline, recommendation) on the document list or detail page?

It is crucial to highlight the key content on the website in a content management system to attract users and increase page views.AnQiCMS (AnQiCMS) provides powerful document recommendation attribute functions, allowing website operators to flexibly mark and display articles.This article will introduce how to cleverly use these recommended attributes in the document list and detail page of Anqi CMS to make your website content more vivid and guiding.### Learn about the recommended features of AnQi CMS AnQi CMS has designed various recommended features for each document

2025-11-07

How to display the detailed content of articles or products and support lazy loading of images?

A Guide to Displaying Content Details and Lazy Loading Images in AnQi CMS in Today's Digital World, the way websites present content directly affects user experience and search engine rankings.Whether it is a detailed article introduction or a beautiful product display, how to present the content efficiently and aesthetically to the visitors and ensure the website loading speed is a challenge that every operator needs to face.AnQiCMS (AnQiCMS) is a powerful content management system that provides us with flexible tools to meet these challenges.This article will delve into how to fully utilize the functions of Anqi CMS

2025-11-07