How to display the associated Tag tag list on the AnQiCMS article detail page?

Calendar 👁️ 65

In website content operation, tags are an important tool for connecting related content, improving user experience, and optimizing search engine rankings.AnQiCMS as an efficient content management system, naturally supports the association function between articles and tags.How can these related tags be clearly displayed on each article's detail page to allow readers to quickly find more interesting content?This article will guide you in easily implementing the tag list display on the article detail page of AnQiCMS.

The importance of tags: connecting content with users

The application of tags is not just about adding a few keywords to the content, it brings value to website operation at multiple levels:

  • Improve user experience:Readers can quickly find all articles related to the theme they are interested in by clicking on the tags on the website, greatly shortening the content discovery path, improving browsing efficiency and user stickiness.
  • Optimize content organization:Tags provide a flexible, flat content classification method.Different from the hierarchical classification system, an article can have multiple tags, thereby achieving multidimensional content cross-referencing and making up for the shortcomings of a single classification system.
  • Help with search engine optimization (SEO):The tag page can be used as the entrance page of the website, providing more keywords for search engines to crawl and increasing the relevance of the page.At the same time, the tag links displayed on the article detail page also constitute important internal links, which help to improve the overall link structure and weight transmission of the website.

Find your article detail page template

We first need to locate the template file that controls the display of the article detail page to display the tag list.Generally, the AnQiCMS article detail page template may vary depending on the model and custom settings you use.

According to AnQiCMS template design conventions, the default template for the article detail page may be located in/template/您的模板目录/{模型table}/detail.html. For example, if you are using the default article model, the template file is likely to be intemplate/default/article/detail.html. If you have set a custom template for a specific article or category, you need to open the corresponding custom template file.

Open this file after, we will add the code to display the labels in this file.

UsetagListLabel get associated labels

AnQiCMS provided a dedicated template tag for retrieving the tag listtagList. This tag feature is powerful, it can get tags based on multiple conditions, and our current goal is to gettags associated with the current article. This requires usingtagListlabel'sitemIdThe parameter value is the ID of the current article.

In the article detail page, AnQiCMS will automatically assign the current article object to the background.archiveVariable. Therefore, the ID of the current article can be obtained througharchive.IdDirectly obtain.

The following is a code snippet for displaying the tag list of the article detail page:

{# 关联标签列表 #}
{% tagList tags with itemId=archive.Id limit="10" %}
    {% if tags %} {# 检查是否有标签,避免显示空的标题 #}
        <div class="article-tags-section">
            <strong>相关标签:</strong>
            {% for item in tags %}
                <a href="{{ item.Link }}" title="查看更多关于{{ item.Title }}的文章" class="tag-item">{{ item.Title }}</a>
            {% endfor %}
        </div>
    {% else %}
        <div class="article-tags-none">
            本文暂无相关标签。
        </div>
    {% endif %}
{% endtagList %}

Code analysis: understand the role of each part.

Let's take a detailed look at each component of this code:

  1. {% tagList tags with itemId=archive.Id limit="10" %}:

    • tagList: This is the core tag provided by AnQiCMS, used to retrieve tag data.
    • tags: You can customize this variable name, which will be used to store the list of labels obtained. In subsequent loops,forwe will usetagsa variable to iterate over each label.
    • itemId=archive.IdThis is the most critical parameter. It tellstagListthe tag to get all tags associated with the current article (viaarchive.Idget its ID).archiveThe object is globally available on the article detail page, representing the article currently being viewed.
    • limit="10": This parameter is used to limit the number of displayed tags. In this example, the article can display up to 10 related tags. You can adjust this number according to your page design and needs.
  2. {% if tags %}...{% else %}...{% endif %}:

    • This is a conditional judgment statement. It checkstagswhether the variable contains any tags.
    • Iftagsis not empty (i.e., the article has associated tags), then executeifThe code within displays the "Related Tags" title and tag list.
    • IftagsIs empty (i.e., the article has no associated tags), then execute.elseThe code within displays the prompt "This article has no related tags." This can avoid the appearance of an empty "Related Tags" title when there are no tags, improving user experience.
  3. <div class="article-tags-section">and<div class="article-tags-none">:

    • These are HTML containers used to wrap tag lists or no tag prompts. They all have a CSS class (article-tags-sectionandarticle-tags-none),方便您后续通过CSS样式表对标签的显示进行美化和布局。
  4. {% for item in tags %}...{% endfor %}:

    • This is a loop statement used to iteratetagListTags retrieved from comments.tagsList.
    • In each iteration,itemEach variable represents a tag object being traversed currently.
  5. <a href="{{ item.Link }}" title="查看更多关于{{ item.Title }}的文章" class="tag-item">{{ item.Title }}</a>:

    • This will generate a clickable link for each tag.
    • {{ item.Link }}: Output the URL address of the current tag. Clicking it will take the user to the list page of all articles under the tag.
    • {{ item.Title }}: Output the name of the current tag.
    • title="...": Add a link totitlea property, when the user hovers over the label, a tooltip text will be displayed, which also helps improve user experience and SEO.
    • class="tag-item": It is the same CSS class, convenient for style control.

Integrated into the article detail page template

Insert the above code snippet into your article detail page template (for exampletemplate/default/article/detail.html) Where do you want to display the tags? Usually, the tag list is placed after the article content or in the sidebar area.

A more complete example might look like this:

`twig

Related articles

How to correctly render Markdown formatted article content in AnQi CMS and display it?

Today, with the increasing efficiency in content creation, Markdown is favored by content creators for its concise syntax and focus on the content itself.AnQi CMS understands this trend and provides powerful features that allow you to easily convert Markdown-formatted article content into exquisite HTML pages and support richer display effects, such as mathematical formulas and flowcharts.

2025-11-08

How to configure the lazy loading effect of images in the AnQiCMS article content?

In AnQiCMS, optimizing website loading speed is a key step to improving user experience and search engine rankings.When the article content contains a large number of images, these images will significantly increase the page loading time.Image lazy loading (Lazy Loading) is an efficient way to solve this problem, it can prevent images from loading until they enter the user's field of vision, thereby speeding up the initial rendering speed of the page.AnQiCMS as a content management system focusing on performance and SEO provides flexible support for lazy loading images in article content.You can configure the template simply

2025-11-08

How to implement 'Previous' and 'Next' document navigation on the AnQiCMS article detail page?

In Anqi CMS, implementing the "Previous" and "Next" navigation functions on the article detail page is a key link in improving user experience, guiding users to delve deeper into the website's content, and also helps optimize the internal link structure of the website, which is greatly beneficial for SEO performance.AnQiCMS has a powerful template system and flexible tag features, making this operation intuitive and efficient.### How to implement 'Previous' and 'Next' document navigation in AnQiCMS AnQiCMS has designed a series of convenient template tags specifically for retrieving information about adjacent documents in the article detail page

2025-11-08

How to display hot articles on the AnQiCMS homepage based on article views?

On AnQiCMS, the homepage is usually the important entry point for visitors to understand the website content and quickly obtain information.Effectively display popular articles, not only to attract users' attention, improve content exposure, but also effectively enhance the user experience of the website and PV (page views).AnQiCMS with its flexible template tags and built-in features makes this operation very simple and intuitive.

2025-11-08

How to implement website in-site search and display article search results in AnQiCMS?

In website operation, the in-site search function plays a crucial role.It can not only help visitors find the information they need quickly, improve user experience, but also through the analysis of search data to understand user needs, optimize content strategy.The AnQi CMS is an efficient content management system that provides a set of intuitive and powerful mechanisms to implement site search and flexibly display search results.The on-site search function of Anqi CMS is designed to be very practical.

2025-11-08

How to display related article recommendations at the bottom of the AnQiCMS article detail page?

In AnQiCMS, adding a related article recommendation feature to the article detail page can not only effectively increase the user's stay time on the website, guide them to discover more interesting content, but also have a positive impact on the website's SEO performance.It is not difficult to achieve this function with the flexible and powerful template tag system provided by AnQiCMS. Understanding AnQiCMS Template Structure In AnQiCMS, the page layout and content display of the website are controlled by template files.

2025-11-08

How to build multi-condition filtering function for article list and display results in AnQiCMS?

In website operation, providing flexible multi-condition filtering functions for article lists can greatly enhance user experience and the discoverability of content.AnQiCMS (AnQiCMS) leverages its powerful content model and rich template tags to make building such features intuitive and efficient.Below, we will delve into how to step by step implement multi-condition filtering and display results of article lists in AnQiCMS.

2025-11-08

How to automatically generate and display a table of contents (TOC) on the AnQiCMS article content page?

In AnQiCMS, automatically generating and displaying the table of contents (TOC) for article content pages not only significantly enhances the user reading experience but also helps search engines better understand the article structure, thereby having a positive impact on SEO.With the powerful and flexible template system of AnQiCMS, it is simpler to achieve this function than you imagine.How does AnQiCMS support automatic directory generation?

2025-11-08