How to display the name, link, and hierarchy of the article category on the article detail page?

Calendar 👁️ 60

AnQi CMS is a flexible and efficient content management system that provides great freedom in content display.For a website, the article detail page not only needs to display the content of the article itself, but also the name, link, and even the hierarchy of the category it belongs to, which are all important components for improving user experience, optimizing website structure, and promoting SEO.Clear categorization information helps users quickly understand the positioning of the article, making it convenient for them to further browse related content and also allows search engines to better crawl and understand the structure of the website.

Next, we will discuss how to elegantly implement the display of the name, link, and hierarchical relationship of the article category belonging to the article detail page in AnQi CMS.

1. Directly obtain classification information from the article details

In AnQi CMS, when you visit the detail page of an article, the system will automatically load various data associated with the article, including information about the category to which the article belongs. By usingarchiveDetailThe tag, we can directly obtain the category object of the current article, and then extract the name and link of the category.

archiveDetailThe tag is used to obtain detailed data of the document. It can not only obtain the title, content, etc. of the article, but also obtain theCategoryobject. thisCategoryobject contains the ID, name, link, and other key information of the category.

Here is the template code snippet to implement this function:

{% archiveDetail currentArchive with name="Id" %} {# 获取当前文章ID,用于确保在文章详情页上下文 #}
<div class="article-category">
    {# 使用archiveDetail标签,并指定name="Category"来获取分类对象 #}
    {% archiveDetail archiveCategory with name="Category" %}
    所属分类:<a href="{{ archiveCategory.Link }}">{{ archiveCategory.Title }}</a>
    {% endarchiveDetail %}
</div>

In this code block:

  • We first pass through{% archiveDetail currentArchive with name="Id" %}Get the current article ID (this step is mainly to clarify that we are on the article detail page context, you can directly skip obtaining the category in fact becausearchiveDetailThe article details page defaults to the current article).
  • Then,{% archiveDetail archiveCategory with name="Category" %}Assign the current article's category information to a namedarchiveCategory.
  • Then, we can go througharchiveCategory.LinkGet the category link, as well as througharchiveCategory.TitleGet the category name and display it on the page.

This method is very concise and efficient, suitable for scenarios where you only need to display the name and link of the direct category of the current article.

2. By category ID, obtain category details independently

Sometimes, we may need to obtain information about a category more flexibly, or when the context on the current page is not clear enough. In this case, we can first obtain the category ID from the article details, and then usecategoryDetailTag to independently query the details of this category.

categoryDetailThe tag allows you to obtain detailed data of the category based on the category ID or URL alias, including its name, link, description, and even the ID of the parent category.

Here is the template code example:

{% archiveDetail currentArchive with name="CategoryId" %} {# 获取当前文章所属分类的ID #}

<div class="article-category-detailed">
    {# 使用categoryDetail标签,通过CategoryId来获取分类信息 #}
    {% categoryDetail categoryInfo with id=currentArchive %}
    分类名称:<a href="{{ categoryInfo.Link }}">{{ categoryInfo.Title }}</a>
    {% endcategoryDetail %}
</div>

In this example:

  • We first use{% archiveDetail currentArchive with name="CategoryId" %}To get the ID of the current article's category and assign it tocurrentArchivethe variable (herecurrentArchivewhich actually stores the category ID).
  • Later,{% categoryDetail categoryInfo with id=currentArchive %}Then use thiscurrentArchive(i.e., category ID) to query and retrieve complete information of the category, and assign it tocategoryInfoVariable.
  • Finally, throughcategoryInfo.LinkandcategoryInfo.Titlewe can display the category link and name.

This method provides greater flexibility, especially when you need to perform further operations based on the category ID.

3. Skillfully use breadcrumb navigation to display the hierarchical relationship (recommended)

For displaying the hierarchical relationship of the article category, Anqi CMS provides a special and very powerful tag -breadcrumb.Breadcrumbs are designed to display the hierarchical structure of page paths, and they can automatically parse the position of the current page and generate a complete navigation path from the homepage to the current page (including all intermediate categories), with each level containing a name and a clickable link.This is the most recommended method for displaying hierarchical relationships.

breadcrumbThe tag is very easy to use, usually just place it in the position on the page where you want to display the breadcrumb navigation.

<div class="breadcrumb-nav">
    {% breadcrumb crumbs with index="首页" title=true %}
    <ol>
        {% for item in crumbs %}
            <li>
                {% if not forloop.Last %} {# 如果不是最后一个元素,则显示链接 #}
                    <a href="{{ item.Link }}">{{ item.Name }}</a>
                {% else %} {# 否则只显示名称(当前页面) #}
                    {{ item.Name }}
                {% endif %}
            </li>
            {% if not forloop.Last %} / {% endif %} {# 添加分隔符,除了最后一个元素 #}
        {% endfor %}
    </ol>
    {% endbreadcrumb %}
</div>

This code:

  • {% breadcrumb crumbs with index="首页" title=true %}It will generate an array namedcrumbsAn array that includes all hierarchical information from the 'Home' page to the current article.index="首页"The parameter defines the starting point as the 'Home' page,title=trueThis indicates that the last element of the breadcrumb will display the title of the current article.
  • ByforLoop throughcrumbsarray, eachitemincludesName(link name) andLink(Link address).
  • forloop.LastIs a built-in variable used to determine whether it is the last element in the loop, commonly used to control the display of links or the addition of separators.

UsebreadcrumbTags are the most convenient and semantic way to display classification levels, as they eliminate the complex logic of manually tracking parent categories and are automatically completed by the system.

Summary

AnQi CMS excels in the flexibility of content display, whether it is to directly obtain the current category name and link from the article details, independently query category information through category ID, or use the powerful breadcrumb navigation tags to display the complete hierarchy, all of which provide intuitive and efficient implementation methods.You can choose the most suitable way based on the specific requirements and complexity of the page design.Recommend using in most casesbreadcrumbTags are used to handle classification level display, as they provide complete information while also greatly simplifying the writing of templates.


Frequently Asked Questions (FAQ)

Q1: Why can't I click or display an error on my category link?

A1:This is usually due to incorrect configuration of pseudo-static rules or the category not setting URL aliases.The AnQi CMS relies on URL rewriting rules to generate friendly URLs, please make sure that your website is correctly configured for URL rewriting, and the category of the article is set in the background (Content Management -> Document Category -> Edit Category -> Other Parameters), and the "Custom URL" field is filled in or automatically generated.If the category ID is removed in the static rule, the link may also be incorrect.

Q2: How can I display only the parent category name of the current category on the article detail page without showing the full breadcrumb and the name of the current category?

A2:You can use it toarchiveDetailGet the current article'sCategoryIdand then usecategoryDetailCombineParentIdattribute to get the information of the parent category. The specific steps are:

  1. First, get the current article'sCategoryId.
  2. Then, usecategoryDetailtag, passed from the previous stepCategoryIdto get the category ofParentId.
  3. IfParentIdis not 0, which means there is a parent category. Then usecategoryDetailthe tag to pass thisParentIdto get the name and link of the parent category. Example code may look like this:
{% archiveDetail currentCatId with name="CategoryId" %}
{% categoryDetail currentCategory with id=currentCatId %}
    {% if currentCategory.ParentId > 0 %}
        {% categoryDetail parentCategory with id=currentCategory.ParentId %}
            父级分类:<a href="{{ parentCategory.Link }}">{{ parentCategory.Title }}</a>
        {% endcategoryDetail %}
    {% else %}
        无父级分类
    {% endif %}
{% endcategoryDetail %}

Q3: How to make the displayed category name link open in a new window?

A3:You just need to add the attribute in the template code to generate the category link,<a>tagstarget="_blank"and it is done.

Related articles

How to correctly display images in the article content of AnQiCMS templates and support lazy loading of images?

In content operation, exquisite images can significantly enhance the attractiveness and reading experience of articles.However, image files are often large, and if not handled properly, they may slow down page loading speed, affect user experience, and even search engine rankings.AnQiCMS fully understands this, providing a flexible way to correctly display images in article content within templates, and supports lazy loading of images to balance aesthetics and performance.### Core: Display images in article content In the AnQiCMS template, to obtain the main content of the article, we mainly rely on `{%

2025-11-08

How to obtain and display the title and detailed content on the article detail page?

Manage website content in Anqi CMS, the article detail page is an important window for displaying core information to visitors.Whether it is corporate news, product introduction, or technical articles, clearly presenting the title and detailed content is the key to improving user experience and information communication efficiency.The Anqi CMS provides intuitive and powerful template tags, making content presentation easy and flexible. ### Understanding Anqi CMS Template Structure Anqi CMS template files are usually stored in the `/template` directory and follow a set of simple naming conventions.for the detail page of an article or product document

2025-11-08

How to declare a temporary variable in AnQiCMS template and use it to display content, improving template flexibility?

In the template creation of Anqi CMS, we often need to display various dynamic content.It is crucial to be proficient in using temporary variables to make templates more flexible and code more concise.The Anqi CMS template engine provides powerful functionality for declaring temporary variables, which helps us better organize and process data, thereby improving the efficiency and maintainability of content display.### Understanding the Value of Temporary Variables Imagine that you need to display processed data at multiple locations on the page, or that a piece of data is used repeatedly in conditional judgments, or that data obtained from a tag needs to be further processed before it can be presented

2025-11-08

How to optimize page layout and content display by using the template inheritance (`extends`) tag?

In AnQiCMS, templates are the foundation for building the appearance and layout of a website.A well-designed template not only makes the website look professional and beautiful, but also greatly enhances the efficiency of content operation and the convenience of website maintenance.Among many powerful template tags, the `extends` (template inheritance) tag is undoubtedly one of the key tools for optimizing page layout and content display.It can help us build a unified and flexible website structure, making content operation and frontend development more effortless.### Understanding `extends`: The core of template inheritance `extends`

2025-11-08

How to retrieve and display the publish time, update time, view count, and comment count of an article?

## Mastering AnQi CMS: A Comprehensive Guide to Article Publishing and Interactive Data Display In website operation, clearly displaying the publication and update time of articles, popularity (page views), and reader feedback (number of comments) can not only effectively improve user experience but also enhance the authority and timeliness of the content.AnQiCMS (AnQiCMS) relies on its flexible template tag system to make the acquisition and display of this key information simple and efficient.This article will explain in detail how to implement these functions in Anqi CMS.### One

2025-11-08

How to display the cover image, thumbnail, or group image of an article on the article detail page?

In Anqi CMS, adding images to the article detail page is an important link to improve the attractiveness of the content and the reading experience, whether it is the cover main image, thumbnail, or multiple group images.Anqi CMS provides a flexible and intuitive way to manage and display these image resources, allowing you to easily achieve diverse visual presentations. ### The Flexible Use of Article Cover Image and Thumbnail In the article detail page, the cover image (Logo) and thumbnail (Thumb) are the most common image elements.They are usually used to represent the main visual content of an article and are widely used on list pages

2025-11-08

How to get and display the list of tags and links associated with the article in the template?

In website operation and content management, article tags (Tag) are key tools for improving content organization, user experience, and search engine optimization (SEO) effects.They can not only help users quickly find relevant content of interest, but also provide clearer content theme information for search engines, thus improving the overall performance of the website.AnqiCMS as an efficient content management system provides intuitive template tags, allowing you to easily obtain and display the list of associated tags and links in the template.

2025-11-08

How to display custom additional field data in the article model to achieve flexible content display?

In Anqi CMS, the flexibility of content is one of its core strengths.We often need to display unique information beyond standard fields such as product SKU codes, publication dates, author information, or specific time and location of events.This personalized data, through the custom additional field feature, can achieve perfect carrying and management.But how to beautifully and flexibly present these meticulously entered custom data on the front end of the website is a focus of many users.This article will guide you to deeply understand the display mechanism of custom fields in Anqi CMS

2025-11-08