How are the `categoryList` and `categoryDetail` tags used to build and display the hierarchical structure of the website?

Calendar 👁️ 67

In AnQi CMS, the hierarchical structure of the website's categories is the core of content organization, which not only affects the user's browsing experience but is also an important part of search engine optimization. To effectively build and display these category structures, we mainly rely on two powerful template tags: categoryListandcategoryDetailThey work together, allowing you to flexibly present clear and organized content categories on the website front-end.

Build a category list:categoryListTag

categoryListThe main function of the label isList one or more content categories on the website.. Whether you want to build the main navigation menu, the sidebar category list, or display popular categories at the bottom of the page,categoryListit can be easily achieved.

When you need to use this tag, it usually starts like this:{% categoryList categories with moduleId="1" parentId="0" %}. Here,categoriesThis is the variable name you specify for this group of classification data, you can name it freely.moduleIdParameters are crucial, as they inform the system about which content model you want to retrieve categories from (for example, the article model ID is usually 1, while the product model ID might be 2).parentIdThe parameter is used to control which level of classification you want to obtain: Set to"0"Indicates getting the top-level category; If you want to get the subcategories under a specific category, you can set it to the ID of the parent category; If you are on a category page and want to get the sibling categories of the current category, you can setparentId="parent".

IncategoryListInside the tag, you can useforLoop through each category item obtained and access its various properties to build your list. For example,item.Titlewill display the category name,item.LinkProvide the URL of the category page, anditem.Descriptionthen you can display the introduction of the category.

Display multi-level category structureIscategoryLista highlight. By nesting again internally.categoryListLabel, and utilizeitem.Idas the subcategory'sparentIdYou can easily build an infinite-level navigation menu. At the same time,item.HasChildrenThe property can help you determine if a category has subcategories, thereby deciding whether to render the next-level menu, making your navigation more interactive.

For example, creating a multi-level category menu might look something like this:

<ul class="main-nav">
    {% categoryList topCategories with moduleId="1" parentId="0" %}
        {% for item in topCategories %}
            <li class="nav-item {% if item.HasChildren %}has-dropdown{% endif %}">
                <a href="{{ item.Link }}">{{ item.Title }}</a>
                {% if item.HasChildren %}
                    <ul class="dropdown-menu">
                        {% categoryList subCategories with parentId=item.Id %}
                            {% for subItem in subCategories %}
                                <li class="dropdown-item"><a href="{{ subItem.Link }}">{{ subItem.Title }}</a></li>
                            {% endfor %}
                        {% endcategoryList %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
    {% endcategoryList %}
</ul>

By such a structure, your website navigation can clearly display the hierarchy of content, making it easy for users to quickly find the information they need.

Get category details:categoryDetailTag

categoryDetailused for labelingGet detailed information of a single category.It is usually on the category page (such aslist-{分类id}.htmlUsed in, to display the title, description, content, or illustration of the current category. Moreover, when you need to refer to the detailed data of a specific category at other locations on the website,categoryDetailAlso very convenient.

The usage of this tag is usually:{% categoryDetail with name="Title" %}. If you call it on the category detail page, it will intelligently retrieve the category information of the current page. If you want to get data for a specific category, you can pass inidortokenparameters, for example{% categoryDetail with name="Description" id="5" %}Will get the description of the category with ID 5.

categoryDetailVery rich information can be obtained, including the category of theId/Title/Link/Description/Content(Introductional text of the category),Logo(Large image or Banner image of the category),Thumb(Category thumbnail), even with additional custom fields in the background. This allows you to design unique and informative layouts for each category page.

For example, at the top of the article category page, you may want to display the name of the current category, its detailed description, and a category Banner image:

<div class="category-header">
    <img src="{% categoryDetail with name='Logo' %}" alt="{% categoryDetail with name='Title' %}" class="category-banner">
    <h1>{% categoryDetail with name='Title' %}</h1>
    <p class="category-description">{% categoryDetail with name='Description' %}</p>
    {% categoryDetail categoryContent with name="Content" %}
    <div class="category-full-content">
        {{categoryContent|safe}}
    </div>
</div>

categoryListwithcategoryDetailcollaboration

These tags are not isolated, they often collaborate to achieve more complex functions. For example, when displaying a document list, each document will be associated with a category ID (item.CategoryId). If you want to display the name and link of the category it belongs to in the document card, you can do so byarchiveListcombine within the loopcategoryDetail:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <div class="article-card">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>分类:<a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{% categoryDetail with name='Title' id=item.CategoryId %}</a></p>
            <p>{{ item.Description }}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

This usage greatly enhances the flexibility and richness of content presentation, making the relationship between documents and categories more intuitive.

Summary

categoryListandcategoryDetailThe tag is indispensable for handling the classification hierarchy structure in AnQi CMS template creation. ThroughcategoryListyou can easily build various forms of classification lists and navigation menus; andcategoryDetailIt allows you to delve deeply into the details of each category, providing users with a more personalized browsing experience.Reasonably use these two tags, not only can it make your website content orderly, but also can significantly improve the overall usability and search engine friendliness of the website.


Frequently Asked Questions (FAQ)

How to set up multi-level category relationships when managing categories in the background?In the Anqi CMS backend content management, when you add or edit categories, there will be an option for 'Parent Category'.By selecting different parent categories, you can easily establish a hierarchical structure.For example, create a "News" category, then select "News" as the parent category under it to create "Domestic News" and "International News", and you will have a multi-level category.

2. Why did I usecategoryListNothing is displayed?This usually has several reasons. First, please checkmoduleIdIs the parameter correct, it needs to match the content model ID of the category you want to display. Secondly,parentIdIs the parameter set properly, for example, if you want to display the top-level category, make sureparentIdWith"0". Finally, confirm that you have indeed created the categories in the background, and that these categories all belong to the specified ones.moduleId.

**3. I want to use a custom template style for the specific category page, should I...

Related articles

How to retrieve and display the detailed information of a single document, including its custom fields, using the `archiveDetail` tag?

In a content management system, effectively displaying the detailed information of a single document is one of the core requirements.Whether it is news articles, product introductions, or service descriptions, users always hope to have a direct and comprehensive understanding of the specific content of each item.AnQiCMS provides a powerful `archiveDetail` tag, allowing you to easily retrieve and display all information of a single document, including your custom exclusive fields.### Retrieve the core information of the document: `archiveDetail`

2025-11-08

How does the `archiveList` tag control the display quantity, sorting method, and pagination logic of the document list?

In AnQi CMS, the `archiveList` tag is undoubtedly a core tool for content display, providing great flexibility and control for the website's content list.Whether you want to display the latest articles on the homepage or implement complex filtering and pagination on the category page, `archiveList` can help us present content accurately through its rich parameter configuration.Next, let's delve into how to use this tag to control the display quantity, sorting method, and the implementation of exquisite pagination logic of the document list.### Control Document Display Quantity

2025-11-08

How to use the various tags built into AnQiCMS to retrieve and display the system information, content list, and details of the website?

How to efficiently display various information when building and managing a website is the key to user experience and operational efficiency.AnQiCMS With its flexible and powerful template tag system, enables content creators and website operators to easily control the acquisition, display, and personalized customization of website content without a deep programming background.This article will delve into the rich tags built into AnQiCMS, showing you how to cleverly use them to retrieve and display the system information, content list, and diverse content of detail pages of the website.Understanding AnQiCMS

2025-11-08

How to customize independent display templates for single pages such as 'About Us' to meet specific display requirements?

In Anqi CMS, in order to make single pages like "About Us" and "Contact Us" have unique display effects, rather than following the unified page layout of the website, we can customize independent display templates for them.This customized capability is a reflection of the flexibility of Anqi CMS, which can help us better shape our brand image, or provide a more suitable display form for specific content.### Overview of AnQi CMS Template Mechanism The AnQi CMS template system is designed to be very intuitive and powerful, based on syntax similar to the Django template engine, which separates the presentation of content from logical control.

2025-11-08

How to manage and display independent single-page content for the `pageList` and `pageDetail` tags?

In website operation, in addition to dynamically updated articles or product lists, we often need to display some relatively fixed and independent content pages, such as "About Us", "Contact Information", "Privacy Policy" or "Service Introduction" and so on.These pages are usually called "single-page content". AnQiCMS provides us with powerful and flexible tools for managing and displaying these pages, especially the core tags `pageList` and `pageDetail`.### Single Page Content: The Foundation of a Website Single page content is an indispensable part of a website

2025-11-08

How to implement content aggregation and thematic display based on `tagList` and `tagDetail` tags?

In content management and website operations, how to efficiently organize and display content is the key to improving user experience and SEO performance.AnQiCMS provides powerful tag features, with the `tagList` and `tagDetail` template tags, it is easy to implement content aggregation based on tags and thematic display, bringing more flexible classification and richer navigation experience to the website.### The role of tags in content aggregation Tags are an important way to organize content in a content management system

2025-11-08

How to generate and control the pagination display effect of the `pagination` tag?

In website operation, when the amount of content is large, how to efficiently and beautifully display these contents while ensuring that users can browse conveniently is the key to improving user experience.If you dump all the content on the same page, not only will it load slowly, but it will also deter visitors.At this moment, content pagination becomes particularly important. It breaks massive information into several pieces, which not only reduces the burden of page loading but also allows users to explore the content they are interested in step by step at their own pace.AnQiCMS provides a powerful and flexible `pagination` tag

2025-11-08

How to implement conditional display and loop display of dynamic content in AnQiCMS template using `if` and `for` tags?

In the Anqi CMS template world, `if` and `for` tags are the foundation for building dynamic and flexible pages.They give the template the ability to display content based on different data conditions, as well as the ability to efficiently loop through data sets, making your website content生动地呈现给visitors vividly.AnQi CMS adopts a template engine syntax similar to Django, making it easy for you, who is familiar with web development, to get started quickly, obtaining data through double curly braces `{{variable}}`, and using `{% tags %}` syntax for conditional judgment and loop control.### Use `if`

2025-11-08