How to integrate a category list in the navigation menu and display product documents under each category?

Calendar 👁️ 54

In AnQi CMS, integrating product categories into the navigation menu and displaying the product documents under them is a key step to improve website user experience and content organization efficiency.This can not only help visitors find the information they need quickly, but also helps search engines better understand the structure of the website.

To achieve this goal, we need to make some basic settings in the Anqi CMS backend and integrate the corresponding code in the template files according to these settings.

Step 1: Back-end preparation - Build content and navigation structure

Ensure that the back-end content structure is clearly established before integrating at the template level.

  1. Establish product content model and classificationThe AnQi CMS supports a flexible content model.If your website is mainly for displaying products, you should have already set up a "product model" (which is usually built-in to the system, or you can customize it).In the 'Content Management' module, go to 'Content Model' to confirm the existence of the 'Product Model'. Next, create a detailed classification system for your product in the "Document Classification" section.For example, you can create "electronics", "home goods", and other first-level categories, and create "phones", "computers", or "kitchen appliances", "bedroom furniture" and other second-level categories under them.Ensure these categories are based on the "product model".

  2. Publish and associate product documentationPost your product documentation under the corresponding category.When adding product documentation, be sure to associate it with the correct category, and fill in the product title, description, images, and any custom parameters, as this information will be displayed on the front end.

  3. Configure website navigationNow, we need to configure the navigation menu in the background “Navigation Settings” so that these product categories can be displayed on the website front end.

    • There will usually be a primary navigation, you can create a first-level navigation named "Product Center" or "All Products".
    • Next, add sub-navigation to this main navigation.Select the link type as "Category Page Link" and then select the specific product category you previously created from the drop-down list (for example, "Electronics", "Home Goods").This, each category item in the navigation menu is linked to the product category in the background.

Step two: Template integration - integrate categories and documents into the navigation.

After completing the background settings, we need to modify the website template files so that this data is displayed correctly on the front end. Usually, the website navigation menu code is locatedtemplateUnder the directorybash.html/header.htmlor a specialpartial/nav.htmlin these files.

The template tag function of Anqi CMS is powerful and easy to use, which can help us easily integrate navigation menus with categorized documents. The core idea is to usenavListLabel retrieves navigation menu data and then traverses each navigation item. If the navigation item is a product category (usually a second-level navigation), we can use this category's ID toarchiveListLabel to retrieve and display the product documents under this category.

Here is a commonly used code example that can be directly applied to your navigation menu template file.

<ul>
    {% navList navList with typeId=1 %} {# 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>
                {# 确保当前子导航项确实是一个分类页面,并且有对应的分类ID #}
                {% if inner.PageId > 0 %}
                    {# 使用archiveList标签获取当前分类下的产品文档 #}
                    {% 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 %}
                {% endif %}
            </li>
            {% endfor %}
        </ul>
        {% endif %}
    </li>
    {% endfor %}
    {% endnavList %}
</ul>

Step 3: Code Analysis and Notes

Let's analyze the template code in detail:

  • {% navList navList with typeId=1 %} This is to get the main navigation list tag.typeId=1This usually refers to the default main navigation category in the background "Navigation Settings". If you have created other navigation categories, please adjust according to the actual situation.typeId. VariablenavListStore all the main navigation items data.

  • {%- for item in navList %}: Iterate over each item in the main navigation.itemRepresents a main navigation item.

  • {%- if item.NavList %}:item.NavListIs the current main navigation item containing a sub-navigation list (i.e., a secondary menu)? In our scenario, these sub-navigations are product categories.

  • {%- for inner in item.NavList %}: Traverse each item in the secondary navigation (product category).innerRepresents a sub-navigation item, that is, a product category.

  • {% if inner.PageId > 0 %}: This line is very critical.inner.PageIdStored the category ID associated with the sub-navigation item (product category). We judge throughPageIdwhether it is greater than 0 to ensure that it is indeed a valid category link.

  • {% archiveList products with type="list" categoryId=inner.PageId limit="8" %}This is the core tag for retrieving product documents.

    • productsIs a custom variable name used to store the list of retrieved product documents.
    • type="list"It indicates that we are getting a static list, not a paged list.
    • categoryId=inner.PageId:This is the key!We will pass the ID of the product category we are currently looping to (inner.PageId) toarchiveListThis allows it to accurately retrieve the product documents under the category.
    • limit="8": Limit the maximum number of product documents displayed under each category to 8, and you can adjust this number according to your design requirements.
  • {% if products %}and{% for product in products %}After obtaining the product document list, first judgeproductswhether the variable has content (i.e., whether there are products under the category), if it does, then continue traversing and displaying the link and title of each product.

With such a structure, your navigation menu can not only display product categories but also list relevant product documents directly under each category, greatly enhancing the practicality and user experience of the website.Remember to clear the system cache after completing the code modification, so that the front-end page can update in time.


Frequently Asked Questions (FAQ)

  1. Why can't I see the product documentation in the navigation menu?First, please check that your child navigation (product category) is correctly associated with the actual product category in the background "navigation settings".Next, confirm if there are any published product documents under the product category you are associated with.categoryIdIs the parameter correctly referencing the sub-navigation item?PageId, as well asarchiveListlabel'smoduleIdDoes it match your product model ID (default is product model). Don't forget to clear the cache to make the changes take effect.

  2. I want to display only a fixed number of product documents under a specific category in the navigation menu, but not all, what should I do?You can inarchiveListUsed in tagslimitParameters to limit the number of displayed items, for examplelimit="5"Indicates that only 5 product documents are displayed. If you want to adjust the order of display, you can useorderFor example, parameters,order="views desc"Sorted by view count in descending order, ororder="id desc"Sorted in descending order by the most recent release.

  3. How to ensure that only the product documents of the lowest-level categories are displayed in my navigation menu?The code example will default to traversing all levels of sub-navigation. If you only want to display product documents under specific category levels, you may need to add some logical judgments in the template code, such as判断innerAn object's property (if there is a hierarchical tag in the background category), or only at the deepest levelforUsing a looparchiveListlabel, not in all sub-loops

Related articles

How to implement nested category display with multiple levels and how to judge if there is a subcategory in the template?

When building a website, a clear and organized content structure is crucial for enhancing user experience and SEO performance.AnQiCMS (AnQiCMS) relies on its flexible content model and powerful template engine, allowing us to easily implement complex multi-level nested display and subcategory judgment, thus creating highly customized navigation and content layouts. ### Backend Settings: Build Category Hierarchy In the Anqi CMS backend, the category management feature (usually located under the "Content Management" menu, below "Document Category") is the foundation for implementing multi-level categorization. First

2025-11-08

How to retrieve and display details of a specific category, including description, content, and Banner image?

When operating a website, we often need to display unique content for different category pages, such as a product category may have a detailed introduction and an eye-catching Banner image, while a news category may focus more on a concise description.AnQi CMS provides a flexible mechanism that allows us to easily retrieve and display detailed information about specific categories, including descriptions, content, and Banner images.### Backend settings are fundamental: enriching categories Before displaying category details on the frontend, we need to fill in this information in the Anqi CMS backend

2025-11-08

How to add and display a captcha in the comment or message form to prevent spam?

When operating a website, spam comments and malicious messages are always a headache, as they not only affect user experience but may also damage the professional image of the website.Fortunately, AnQi CMS provides a simple and effective way to solve this problem - that is to add a captcha to the comment or message form.This can greatly enhance the security of the website, filtering out most automated spam information.Below, let's take a detailed look at how to add a captcha to your comment and message form in Anqi CMS.This process can be divided into two steps, which is very intuitive and easy to operate.### Step 1

2025-11-08

How to retrieve and display the list of friend links of a website?

In website operation, friendship links play an important role in connecting each other, promoting traffic, and improving search engine rankings.A well-maintained, clear display of the friendship link area, which not only reflects the openness of the website, but also provides users with more valuable jump paths.AnQiCMS provides users with a convenient friend link management feature, allowing you to easily obtain and display these links on your website. ### Manage your friend links: Backend settings Before starting the front-end display, we need to make sure that the friend links have already been configured in the Anqi CMS backend. Usually

2025-11-08

How to obtain and display the links and titles of the previous and next articles?

When we manage and publish content in Anqi CMS, in order to enhance the user experience and content discoverability of the website, it is usually necessary to provide the function of navigating to the 'previous article' and 'next article' on the article detail page.This not only encourages readers to continue browsing the content within the site, but also provides a good internal link structure for search engine optimization (SEO).The Anqi CMS provides a very concise and intuitive template tag, allowing us to easily meet this requirement.### Core Functionality: `prevArchive` and `nextArchive`

2025-11-08

How to retrieve and display the Logo, thumbnail, and slideshow group on a single page?

In Anqi CMS, single pages (such as "About Us", "Contact Us", etc.) can not only carry rich text information but also greatly enhance the attractiveness and professionalism of the page through visual elements.Retrieve and display the Logo, thumbnail, and slideshow group on a single page, which is a key step to optimize the page display effect.AnQi CMS provides flexible template tags, allowing you to easily achieve these functions.### Understand the composition of visual elements on a single page In Anqi CMS, each single page can have exclusive visual elements to meet different display needs

2025-11-08

How to display copyright information and link to the record number at the bottom of the website?

Clearly display copyright information and filing number at the bottom of your website, which is not only a legal requirement but also a key factor in enhancing the professionalism and user trust of the website.AnQi CMS as an efficient content management system, fully considers these details, allowing you to easily manage and present these important site information. ### Understanding the Importance of Copyright Information and Filing Numbers The copyright statement at the bottom of the website, like a brand watermark, clearly identifies the ownership of the content to visitors, effectively protecting your original achievements.As for websites operating in mainland China

2025-11-08

How to dynamically control the display of content in the template based on conditional logic (if/else)

In AnQiCMS template design, it is possible to flexibly control the display of content based on different conditions, which is the key to achieving website personalization and dynamic display.Whether it is to decide whether to display the picture according to whether the article has a thumbnail, or to display specific content based on the user's role, conditional logic can provide strong support.AnQiCMS uses a syntax similar to the Django template engine, which makes it very easy for webmasters familiar with web development to get started quickly.### Master the basic conditional logic in AnQiCMS templates AnQiCMS

2025-11-08