How to use AnQiCMS tags to display categories and documents in the navigation menu?

Calendar 👁️ 74

In AnQiCMS, the website's navigation menu is not only an important entry for users to explore content and understand the website structure, but also a key for search engines to crawl and understand the hierarchical relationship of the website.By utilizing the powerful template tag function of AnQiCMS, we can easily display categories and documents dynamically in the navigation menu, thereby constructing a navigation that is both beautiful and efficient.

1. Preparation work on the back-end: building the navigation skeleton

Before delving into the template code, we need to make some basic configurations in the AnQiCMS backend.In the end, the data that front-end tags can obtain and display is carefully organized by the backend.

  1. Create and manage navigation categoriesFirst, enter the AnQiCMS backend, find“Background Settings”below“Navigation Settings”. The system will have a default "default navigation" category, but you can also customize more navigation categories as needed, such as "footer navigation", "sidebar navigation", etc.Each category represents a set of independent navigation menus, convenient for you to call at different locations on the website.

  2. Add navigation links, associate categories and documentsAfter selecting or creating a navigation category, the next step is to add specific navigation links.Click the "Add new navigation" or edit an existing navigation item, and you will see the "Link type" option.This is the key point:

    • “Built-in links”: Suitable for pointing to the homepage, various models (such as article models, product models) and other homepages.
    • “Category page link”This is mainly used to display categories and documents in navigation.When you select this type, the system will allow you to select an existing category or a single page as the navigation target.After you select a category as a navigation link, AnQiCMS will allocate one internally for itPageId, this ID will be very useful in the template.
    • “External link”If you need to link to an external site or a custom URL, you can use this option.

    By selecting your article category, product category, or specific single page through the "Category Page Link" and setting the "Display Name", a solid foundation for front-end navigation is laid.You can set up a primary navigation and also create a secondary dropdown menu by selecting "parent navigation".AnQiCMS currently supports up to two levels of navigation links.

Secondly, at the template level: use tags to flexibly present content.

After the background configuration is completed, we will need to use AnQiCMS tags in the template file to dynamically display these navigation items. The AnQiCMS template syntax is similar to Django, and variables are enclosed in double curly braces{{变量}}Using single curly braces and percentage signs for logical control{% 标签 %}.

In your template file (usuallybash.htmlIn a specific navigation header file) we can usenavList/categoryListandarchiveListThese core tags.

  1. Basic navigation menu: Only shows first-level navigation linksThe simplest navigation menu only contains top-level navigation items set in the background. We can use them directly.navListtags to get them.

    {% navList navs %}
    <ul>
        {%- for item in navs %}
            <li class="{% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{item.Title}}</a>
            </li>
        {% endfor %}
    </ul>
    {% endnavList %}
    

    here,navsis fornavListVariables defined by tags, throughforLoop throughnavsarray,item.LinkProvide link addresses,item.TitleDisplay navigation names.item.IsCurrentIt can help us determine whether the current page is the navigation item, thereby addingactiveThe class name is highlighted.

  2. Advanced navigation menu: drop down to display subcategoriesIf your navigation design needs to implement a secondary dropdown menu, and the content of the secondary menu is a subcategory under a primary category, then you cannavListnested in the loopcategoryList.

    Assuming your background navigation has a primary navigation called "Product Center" that links to a main product category, and the secondary navigation links to several subcategories under that main category. When the primary navigation'sitem.NavListWhen it exists, we can further traverse these secondary navigation items. If the secondary navigation item is a "category page link", theninner.PageIdit will correspond to the ID of the category.

    <ul>
        {% navList navList with typeId=1 %} {# 假设您的主导航类别ID是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 %} {# 检查是否关联了分类/页面 #}
                        {% categoryList categories with parentId=inner.PageId %} {# 获取二级分类下的子分类 #}
                        {% 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 %}
        {% endnavList %}
    </ul>
    

    In this code,item.NavListUsed to loop the secondary navigation of the background configuration. If a secondaryinnernavigation item is associated with a category (inner.PageId > 0), we can utilizecategoryListtags, throughparentId=inner.PageIdDynamically retrieve the subcategories under the category, thereby achieving a deeper level of dropdown menu display.

  3. Advanced navigation menu: dropdown to display document listIn addition to displaying subcategories, you may also want to directly display a document list under a certain category in the dropdown menu, for example, displaying the latest news under the "News Center" dropdown. This can also be achieved bynavListNested in ChinesearchiveListto achieve.

    <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" %} {# 获取该分类下的最新8篇文档 #}
                    {% if products %}
                    <ul class="nav-menu-child-child">
                        {% for product in products %}
                        <li><a href="{{product.Link}}">{{product.Title}}</a></li>
                        {% endfor %}
                    </ul>
                    {% endif %}
                    {% endarchiveList %}
                </li>
                {% endfor %}
            </ul>
            {% endif %}
        </li>
        {% endfor %}
        {% endnavList %}
    </ul>
    

Related articles

How to control the display sorting and pagination of AnQiCMS comment list?

In AnQi CMS, efficiently managing and displaying website comments is crucial for enhancing user interaction and optimizing content experience.The display order and pagination settings of the comment list directly affect the user's experience when browsing comments.This article will give you a detailed explanation of how to accurately control the sorting and pagination of comments in AnQiCMS. ### Understanding the Comment List Template Structure Firstly, we need to clarify the position of the comment list in AnQiCMS.

2025-11-07

How to filter and display AnQiCMS document list according to category ID and recommendation attributes?

Manage website content in AnQiCMS, often need to display document lists according to different conditions.Whether you want to display the latest articles of a specific category on the homepage or highlight some recommended content in the sidebar, the system provides flexible tools to help us achieve this.Today, let's talk about how to cleverly use category ID and recommendation attributes to accurately filter and display the document list you want.

2025-11-07

How to display category introduction, Banner image and thumbnail on AnQiCMS category page?

In website operations, the category page is not only an aggregation of content, but also an important entry for users to understand the website structure and explore specific topics in depth.A well-designed, informative category page that can significantly improve user experience and search engine optimization (SEO) effectiveness.AnQiCMS provides flexible features, allowing us to easily display category descriptions, banner images, and thumbnails on the category page, giving your website's category page a fresh look.Understanding AnQiCMS's category page and template structure In AnQiCMS

2025-11-07

How to display AnQiCMS single-page content and related images?

In website operation, we often need to create some independent pages, such as "About UsThese pages contain relatively fixed content, do not belong to the conventional article or product list, AnQiCMS (AnQiCMS) classifies them as "single page" and provides a very convenient management and display method.Through this system, you can easily publish and update this content, while flexibly controlling their display styles and image presentation.

2025-11-07

How to configure the page Title, Keywords, Description of AnQiCMS to optimize search engine display?

In website operation, making your content stand out in search engines is a key step to gaining traffic.And the page title (Title), keywords (Keywords), and description (Description), which we often call TDK, are important elements for communicating with search engines.AnQiCMS is a system focused on enterprise content management, fully aware of the value of TDK configuration for SEO, and therefore provides flexible and powerful functions to help us easily optimize the display of our website in search engines.### Why is TDK configuration so important

2025-11-07

How to use the Canonical URL feature of AnQiCMS to avoid content duplication display issues?

In website operations, we often encounter a tricky problem: content duplication.This does not refer to manually copying and pasting the article, but rather to the fact that the same content can be accessed through multiple different URL addresses due to various technical reasons.For search engines, this can cause confusion, as they are not sure which URL is the official version of the content, which may scatter the ranking weight of the page, reduce the efficiency of the crawler, and even affect the overall SEO performance of the website.Luckyly, AnQiCMS provides a powerful and convenient feature——Canonical

2025-11-07

How to use AnQiCMS built-in TDK tags to dynamically set page SEO information?

As an experienced website operator, I am well aware of the importance of Search Engine Optimization (SEO) for website visibility and traffic growth.In SEO work, the reasonable setting of TDK (Title, Description, Keywords) tags is undoubtedly the cornerstone of the cornerstone.A clear and accurate TDK that can not only help search engines better understand the page content, but also attract users to click on the search results.

2025-11-07

How to correctly configure the pseudo-static rules in AnQiCMS to generate URLs that are friendly to users and search engines?

In website operation, a URL structure that is friendly to both users and search engines is crucial.It not only allows visitors to understand the page content at a glance, but also makes it convenient for search engines to crawl and understand your website, which directly affects the SEO performance and user experience of your website.AnQiCMS (AnQiCMS) knows this well, therefore it is built with powerful pseudo-static features, allowing you to easily customize the URL of your website.Next, we will explore how to correctly configure the pseudo-static rules in AnQiCMS to generate those beautiful and practical URLs.

2025-11-07