How to build and display the AnqiCMS multi-level website navigation list, and support custom styles and subtitle display?

Calendar 👁️ 61

Building a highly efficient, intuitive, and user-friendly website cannot do without a well-designed navigation system.In AnQiCMS, building a multi-level website navigation list, which supports custom styles and subtitle display, is a powerful and flexible feature.It allows content operators to easily create menu structures that adapt to various complex scenarios based on business needs.

The core advantages of AnQiCMS navigation system

AnQiCMS provides rich options for navigation construction, which is due to its high-performance architecture based on the Go language and flexible template engine.The built-in navigation management function allows users to intuitively configure the navigation structure without writing complex code.At the same time, the powerful Django template engine syntax allows front-end developers to easily convert background configurations into beautiful navigation with custom styles and dynamic effects.It is particularly noteworthy that AnQiCMS supports multi-site management, which means you can independently configure navigation for different sites to achieve fine-grained operation.

Step 1: Configure the navigation menu in the background

The navigation configuration of AnQiCMS is mainly focused on the "Website Navigation Settings" in the background. Here, you can freely combine navigation elements like building blocks.

  1. Manage navigation categories:Imagine that your website may not only have a main navigation, but also a footer navigation or sidebar navigation.AnQiCMS allows you to create multiple navigation categories, such as top main navigation, footer navigation, side service, etc.By customizing navigation categories, you can distinguish navigation content at different locations, making it easier to manage and call.
  2. Add Navigation Link:After selecting or creating a navigation category, you can start adding specific navigation links.
    • Display Name and Subtitle:Each navigation item has a "display name", which is the main text displayed to the user on the front end.If you need to display a second language, a brief description, or additional information at the same time for a navigation item, you can fully utilize the 'Subheading Name' field.For example, the main title is "Contact Us", and the subtitle can be "Contact Us".
    • Link Type:AnQiCMS provides three flexible link types:
      • Built-in links:Including the homepage, article model homepage, product model homepage, and other commonly used pages, it conveniently and quickly points to the core functions of the system.
      • Category page links:You can choose any article category, product category, or single page created on the website as a navigation target, ensuring that navigation is closely related to the content structure.
      • External links:Allow you to add any URL within or outside the site, which is very useful for linking to external cooperative sites, social media pages, or specific marketing landing pages.
    • Hierarchical relationship:AnQiCMS supports navigation links up to two levels, that is, a main navigation item can contain one level of sub-navigation items.By setting 'parent navigation', you can easily build this parent-child level menu structure.
    • Display order:Each navigation item can be adjusted for its front-end arrangement position via "Display Order". The smaller the number, the closer to the front it appears, allowing you to precisely control the menu layout.

Step two: Call the navigation list in the template

After the background configuration is completed, the next step is to display these data on the website front-end. AnQiCMS template tag system makes this process very intuitive, among whichnavListThe tag is used to call the navigation list core.

In your template file (usuallybase.htmlOr specificheader.htmlFragment) You can use the following method to call navigation data:

{% navList navs with typeId=1 %}
    <ul>
        {%- for item in navs %}
            <li class="{% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{ item.Title }}</a>
                {%- if item.SubTitle %}
                    <span class="sub-title">{{ item.SubTitle }}</span>
                {%- endif %}
                {# 判断是否有子级导航 #}
                {%- if item.NavList %}
                    <dl class="sub-menu">
                        {%- for subItem in item.NavList %}
                            <dd class="{% if subItem.IsCurrent %}active{% endif %}">
                                <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                {% if subItem.SubTitle %}
                                    <span class="sub-title-child">{{ subItem.SubTitle }}</span>
                                {% endif %}
                            </dd>
                        {%- endfor %}
                    </dl>
                {%- endif %}
            </li>
        {%- endfor %}
    </ul>
{% endnavList %}

In the code above:

  • {% navList navs with typeId=1 %}Here is thetypeIdThe parameter corresponds to the ID of the "navigation category" in the background. If you want to call the "top main navigation", make sure the ID of the category in the background is 1.navsThis is the variable name defined for this navigation list data.
  • {% for item in navs %}: This is a loop used to iterate through all top-level navigation items.
  • item.Titleanditem.Link: Retrieve the main title and link address of each navigation item.
  • {% if item.SubTitle %}: Check if the navigation item has set a subtitle, and display it. You can add a specific CSS class, such assub-title.
  • {% if item.NavList %}This condition judgment is the key to building the second-level navigation. If the current navigation item has a sub-level list (i.e.,NavListIf not empty, then enter the sub-level loop.
  • {% for subItem in item.NavList %}:Again, this time it is to iterate over all the child navigation items under the current top-level navigation item.
  • item.IsCurrentandsubItem.IsCurrentThis is a very practical attribute provided by AnQiCMS. When the user visits a page that matches the link of a navigation item,IsCurrentit will automatically be set totrueYou can use it to add for the currently active navigation itemactiveCSS classes to highlight.

Step 3: Implement multi-level navigation and custom styles

AnQiCMS provides all the data needed to generate the navigation HTML structure. Custom styles are mainly implemented through CSS.

  • HTML structure with CSS:In the above template code, we have adopted a common<ul><li><a>and<dl><dd><a>nested structure to build two-level navigation. You can add custom class names (such assub-menu,sub-titlewait) then write the corresponding CSS rules to implement from simple text styles to complex dropdown menu animation effects. For example, you can usesub-menuClass to control the display/hide, background color, border, and other settings of the secondary menu.
  • Flexible use of subtitles: item.SubTitleThe field is not only used to display the second language, but can also be used as a brief description for navigation items.In CSS, you can define different font sizes, colors, or positions for subheadings to make them auxiliary navigation information and enhance the user experience.

Advanced application scenarios: integrating dynamic content into navigation

The strength of AnQiCMS also lies in the ability to combine the flexibility of the content model with the navigation system. For example, if your needs go further, and you want to directly display a list of products or articles under a specific category in the navigation dropdown menu, you canitem.NavListwithin the nested loop againarchiveListorcategoryList.

For example, display the latest articles of the category under the secondary navigation item:

`twig {# ... top navigation loop ... #}

            {%- if item.NavList %}

Related articles

How to customize the homepage title, keywords, and description through AnqiCMS's TDK tags to improve search engine display?

In website operation, it is crucial to have your website displayed better in search engines, and the TDK (Title, Description, Keywords) tags on the homepage are the core to achieve this goal.AnqiCMS as a SEO-friendly content management system provides intuitive and powerful features to help you easily customize these key elements.By cleverly setting the homepage TDK, you can not only improve the visibility of the website in the search results, but also attract more target users to click and visit.### Understand TDK

2025-11-09

How to display the contact information set in the AnqiCMS backend on the front page and support custom parameter display?

A website can effectively convey information, one of the core elements being that visitors can easily find the contact information.Whether it is in the footer of the website, a special "Contact Us" page, or in the article content, clear and clear contact information is the key to improving user experience and building trust.AnqiCMS (AnqiCMS) with its flexible and customizable features allows you to easily manage this information in the background and display it on the front page, even supporting custom parameters to meet various business needs.Next, let's take a look at how to use the AnqiCMS website front page on your site

2025-11-09

How to call and display AnqiCMS system configuration information on the front page, such as the website name, Logo, or filing number?

When building and managing a website, we often need to ensure that core brand information, such as the website name, Logo, and the registration number required by laws and regulations, remains consistent across all pages of the website and can be updated at any time.AnqiCMS provides a直观而强大的template system, making it very simple and efficient to call and display these global configuration information on the front page.

2025-11-09

How to protect the original copyright of the "Anti-collection and Watermark Management" function of Anqi CMS when displaying content on the front end?

In today's era of泛滥in digital content, the value of original content becomes increasingly prominent.Whether it is an article written with hard work or a carefully photographed picture, every original work embodies the sweat and wisdom of the creator.However, the problem of content being randomly collected and images being used without compensation has always been a headache for many website operators and self-media creators.This not only harms the legitimate rights and interests of the original creators, but may also make it difficult for original content to obtain the应有的 ranking in search engines, even affecting brand credibility.AnQi CMS deeply understands the importance of original content for enterprises and self-media, it is not just a content publishing platform

2025-11-09

How to implement breadcrumb navigation in AnqiCMS templates and control the display of the home page name and document title?

In website operation, a clear navigation path is crucial for user experience and search engine optimization (SEO).Breadcrumb Navigation as an auxiliary navigation method can directly tell users where the current page is in the website structure, effectively reduce the bounce rate, and help search engines better understand the website hierarchy.

2025-11-09

How to use the AnqiCMS category list tag to display article/product categories by level or model on the front end?

It is crucial to organize and present information efficiently in website content management.AnqiCMS provides a powerful template tag system, where the `categoryList` tag is a core tool for displaying articles or product categories flexibly.By mastering the use of this tag, users can easily build a clear and functional classification navigation on the front end, whether displaying by level or filtering according to the content model (such as articles, products), they can handle it with ease.### Get to know `categoryList`

2025-11-09

How to accurately call and display the detailed information of a specific category in AnqiCMS on the front page, including the description and Banner image?

In AnqiCMS (AnqiCMS), the need to accurately call and display detailed information about a specific category on the front page, such as the category description and its exclusive Banner image, is a common requirement.This can make the structure of the website content clearer, as well as improve user experience and the website's SEO performance.Benefiting from AnqiCMS flexible template tag system, achieving this goal is actually very direct. We mainly use a core template tag——`categoryDetail`.

2025-11-09

How to use AnqiCMS's single page list tag to flexibly display independent pages such as 'About Us' on the front end?

In modern website operations, pages like "About Us", "Contact Information", and "Terms of Service" are independent pages that carry the basic information and brand image of the website. Although they are not updated often, they are crucial.AnqiCMS provides a flexible single-page management feature, combining its powerful template tag system, we can easily display these independent pages on the front end and customize them as needed.

2025-11-09