How to display the name, description, content, and link of the category?

Calendar 👁️ 72

When building a website, categorization information is not only the skeleton of the content, but also the key to user navigation, search engine optimization (SEO), and improving user experience.AnQiCMS (AnQiCMS) with its flexible template engine allows you to easily display categories, descriptions, content, and links on the website front-end, thereby providing visitors with a clear navigation path and rich information for search engines to better understand your website structure.

This article will delve into how to flexibly call and display the category information of your website in the AnQiCMS template using several core tags.

Core tags:categoryDetailwithcategoryList

In AnQiCMS, there are mainly two tags used to display category information:

  • categoryDetailWhen you need to display detailed information (such as category name, description, content, Banner image, etc.) on a category page itself, or when you know a specific category ID, categoryDetailTags are your helpful assistants.
  • categoryListIf you want to build a navigation menu, sidebar category list, or display subcategories under a specific content model on the homepage,categoryListThe tag can be put to use, it can iterate and list multiple categories.

Next, we will learn in detail how to use these two tags to display the various information of categories.

Display detailed information of a single category

Suppose you are editing the detail page template of a category (for example/template/{您的模型表名}/list.htmlOr a custom category template), you want to display various detailed data of the current category here.

1. Show category name (Title)

The category name is its most basic identifier. You can use the following method to obtain and display the name of the current category:

<div>
    <h1>{% categoryDetail with name="Title" %}</h1>
</div>

If you need to retrieve the name of a specific ID category or want to assign the name to a variable for subsequent use, you can do it like this:

{# 获取ID为10的分类名称 #}
<h2>特定分类名称:{% categoryDetail with name="Title" id="10" %}</h2>

{# 将当前分类名称赋值给一个变量 #}
{% set currentCategoryName = categoryDetail with name="Title" %}
<p>当前分类名称是:{{ currentCategoryName }}</p>

2. Display the category description (Description)

Category descriptions are usually used to briefly summarize the category topic, which is very helpful for SEO and user understanding.

<meta name="description" content="{% categoryDetail with name="Description" %}">
<p>分类简介:{% categoryDetail with name="Description" %}</p>

3. Display category content (Content)

If your category has filled in detailed content in the background (for example, using rich text editor-written introduction text), you canContentThe field should display it. It is especially important to note that the category content may contain HTML tags. To ensure that these tags are parsed correctly by the browser rather than displayed as plain text, you need to use|safefilter.

<div class="category-content">
    {% set categoryContent = categoryDetail with name="Content" %}
    {{ categoryContent|safe }}
</div>

4. Display category link (Link)

Category links are crucial for guiding users and search engines to the category page. They are usually used for<a>label'shrefProperty.

<a href="{% categoryDetail with name="Link" %}">点击查看更多</a>

When building breadcrumb navigation, you will also often use category links:

{% breadcrumb crumbs with index="首页" %}
<ul>
    {% for item in crumbs %}
        <li><a href="{{item.Link}}">{{item.Name}}</a></li>
    {% endfor %}
</ul>
{% endbreadcrumb %}

5. Display category-related images (Banner image, thumbnail)

Support for setting thumbnail images in AnQi CMS categories (Thumb), Banner image (Logo) and a set of Banner carousel images (Images)

  • Category thumbnail/Banner image (Thumb/Logo):

    <img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}" />
    <img src="{% categoryDetail with name="Thumb" %}" alt="{% categoryDetail with name="Title" %}" />
    
  • Category Banner group image (Images):due toImagesIt returns an array of image addresses, you need to useforLoop to traverse and display them, which is very suitable for making a carousel.

    <div class="category-banner-carousel">
        {% categoryDetail categoryImages with name="Images" %}
        {% for imageUrl in categoryImages %}
            <img src="{{ imageUrl }}" alt="{% categoryDetail with name="Title" %}" />
        {% endfor %}
        {% endcategoryDetail %}
    </div>
    

6. Display custom fields of categories

If you have added custom fields to the category model in the background, you can go throughExtraField or directly use the custom field name to call.

{# 循环显示所有自定义字段 #}
{% categoryDetail extras with name="Extra" %}
<div class="category-custom-params">
    {% for field in extras %}
        <div>
            <span>{{ field.Name }}:</span>
            <span>{{ field.Value }}</span>
        </div>
    {% endfor %}
</div>

If you only care about a specific custom field, for example, if you define a field named "contact email", its calling field name iscontactEmailyou can use it directly:

<p>分类联系邮箱:{% categoryDetail with name="contactEmail" %}</p>

Display category list information

When you need to display multiple categories, such as in the website's navigation menu, sidebar, or some block on the homepage,categoryListtags are very useful.

1. Get the top-level category list

It is usually used to build the main navigation menu. You need to specifymoduleIdTell the system to get the category under which content model (for example, article model ID is 1, product model ID is 2) and setparentId="0"To get the top-level category.

<nav class="main-navigation">
    <ul>
        {% categoryList categories with moduleId="1" parentId="0" %}
        {% for item in categories %}
            <li {% if item.IsCurrent %}class="active"{% endif %}>
                <a href="{{ item.Link }}">{{ item.Title }}</a>
            </li>
        {% endfor %}
        {% endcategoryList %}
    </ul>
</nav>

In the above example,item.IsCurrentIt can help you determine if the current loop category is the category of the page the user is visiting, so that you can add a highlight style to it.

2. Get the subcategory list

In many cases, you may need to display the subcategories under the main category. This can be used again inside a loop.categoryListTag implementation.

<nav class="main-navigation">
    <ul>
        {% categoryList topCategories with moduleId="1" parentId="0" %}
        {% for topCategory in topCategories %}
            <li {% if topCategory.IsCurrent %}class="active"{% endif %}>
                <a href="{{ topCategory.Link }}">{{ topCategory.Title }}</a>
                {# 判断是否有子分类,如果有,则再次循环 #}
                {% if topCategory.HasChildren %}
                    <ul class="sub-menu">
                        {% categoryList subCategories with parentId=topCategory.Id %}
                        {% for subCategory in subCategories %}
                            <li {% if subCategory.IsCurrent %}class="active"{% endif %}>
                                <a href="{{ subCategory.Link }}">{{ subCategory.Title }}</a>
                            </li>
                        {% endfor %}
                        {% endcategoryList %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
        {% endcategoryList %}
    </ul>
</nav>

exceptTitleandLinkYou can also display other information in the list, such as the number of documents included in the categoryArchiveCount:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <p><a href="{{ item.Link }}">{{ item.Title }}</a> ({{ item.ArchiveCount }}篇文章)</p>
    {% endfor %}
{% endcategoryList %}

Practical tips

  • SEO OptimizationDescription of the category (DescriptionIncorporating keywords rationally can effectively improve the performance of the classification page in search engines. At the same time, a clear classification link structure is crucial for search engine crawling.
  • HTML content securityWhen you display categories'Contentfields, remember to use|safefilters. This is to prevent background editing

Related articles

How to retrieve and display the custom parameter fields of the document in Anqi CMS?

AnQi CMS is loved by content operators for its excellent flexibility and highly customizable nature.In daily website management, we often encounter scenarios where it is necessary to add exclusive attributes for different types of content (such as articles, products, events, etc.)At this time, the document custom parameter field function of Anqi CMS can fully display its strength, allowing us to expand the structure of content according to business needs, thus achieving more personalized and rich display effects.

2025-11-08

How to display the links to the previous and next documents on the document detail page?

In website operation, providing a smooth user experience is crucial, and the previous and next navigation on the document detail page is the key to improving user experience and guiding users to deeply browse the website content.In AnQiCMS (AnQi CMS), implementing this feature is simple and efficient, it comes with dedicated template tags that allow you to easily add this practical feature to your website content. ### The Importance of Navigation Between Articles After users finish reading a document, they often want to find related or the next article to get more information.

2025-11-08

How to retrieve and display the Tag list associated with the document in AnQi CMS?

The AnQi CMS provides a flexible and powerful Tag feature in content management, which can not only help you better organize content but also effectively improve the website's SEO performance and user experience.This article will introduce how to manage and retrieve the Tag tag list associated with documents in Anqi CMS and display it on your website front-end. ### Backend Tag Management: Effective Classification and Association Tag management in Anqi CMS is intuitive and convenient.You can find the 'Document Tag' feature under the 'Content Management' menu in the background.

2025-11-08

How to display the publish time, update time, view count, and category of the document?

In AnQiCMS, flexibly displaying content is one of its core advantages, which not only concerns the user experience but also directly affects the website's SEO performance.The document's publication time, update time, view count, and category information are often the focus of users and important indicators for search engines to evaluate the timeliness and relevance of content.It's good that AnQiCMS provides us with intuitive and powerful template tags, making the display of this information very simple.

2025-11-08

How to get and display category thumbnails or Banner carousel?

The attractiveness of visual content is crucial in website operation.A well-designed category thumbnail and an eye-catching banner carousel not only beautifies the website interface but also effectively guides users to browse, enhancing the overall professionalism and user experience of the website.AnQiCMS (AnQiCMS) offers powerful and flexible features that allow you to easily manage and display these important visual elements.This article will provide a detailed introduction on how to obtain and display category thumbnails or Banner carousel in Anqi CMS.

2025-11-08

How to get all category lists under a specified model in AnQi CMS?

AnQi CMS with its flexible content model design makes content management efficient and elastic.Whether it is an enterprise official website, a marketing website, or a personal blog, there may be a need to display the corresponding category list according to different content models (such as articles, products, or custom models).Understanding how to accurately retrieve these categories in the template is a key step in fully utilizing the powerful functions of AnQi CMS.In AnQi CMS, the content model is the foundation of organizing content.

2025-11-08

How to implement multi-level category nesting display in Anqi CMS?

The organization of website content is crucial for user experience and information retrieval efficiency.A clear and logical classification system can help visitors quickly find the information they need, and also lay a good foundation for the website's SEO.In Anqi CMS, implementing nested display of multi-level categories is the key to building this efficient content architecture.It is not just to list categories simply, but also to modularize and organize the content through hierarchical relationships, whether it is product display, article archive, or service introduction, it can be presented to users in a more intuitive way.

2025-11-08

How to retrieve custom fields of a category on the category detail page?

When managing website content in AnQi CMS, we often need to make the category page not just a simple aggregation of document lists, but also able to carry more exclusive information to better guide users or display the characteristics of the category.It is particularly important to add and obtain custom fields for categorization at this time.By using these custom fields, you can make each category page unique, whether it's displaying a specific banner image, contact information, or the unique properties of the category.

2025-11-08