How to display all related Tag tags on the article detail page?

Calendar 👁️ 61

As a professional deeply familiar with the operation of Anqi CMS, I know that every detail of content creation and presentation is related to user experience and the SEO performance of the website.Properly displaying associated Tag tags on the article detail page not only helps readers quickly understand the core of the article and discover more related content, but also has a positive effect on search engine optimization.Below, I will elaborate on how to implement this feature on the article detail page of Anqi CMS.

AnQi CMS Tag tag feature overview

The AnQi CMS provides powerful Tag label features, allowing content creators to add multiple tags to articles, products, and other content.These tags are similar to thematic keywords, which can associate related content across categories and models, providing users with more flexible navigation and content discovery paths.When editing articles in the background, we can manually enter or select existing tags to associate them with the article.This feature has been enhanced since version 2.1.0 of AnQiCMS, making content management and association more convenient.

Locate the article detail page template

To modify the display content of the article detail page, we first need to find the corresponding template file. According to the template design conventions of AnQi CMS, the template for the article detail page is usually located in the model subdirectory under the template directory, for example{模型table}/detail.htmlor{模型table}_detail.html. This is typically for the article modelarticle/detail.htmlorarticle_detail.html. If you have set a custom template for a specific article or category, you need to modify the corresponding custom template file.

UsetagListTemplate tag retrieves article associated tags

In the AnQiCMS template system, we use specific template tags to retrieve and display data. To display all associated Tag tags on the article detail page, we need to usetagListThe tag. This tag is used to retrieve the list of tags of the document.

tagListThe usage of the tag is relatively intuitive, it has a key parameteritemId. In the context of the article detail page,itemIdIf the parameter is not explicitly specified, it will default to reading the current document's ID, thereby automatically obtaining the tags associated with the current article.This makes it very convenient to call tags on the article detail page.

Call in templatetagListThe basic structure is as follows:

{% tagList tags %}
    {% for item in tags %}
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    {% endfor %}
{% endtagList %}

In this code block:

  • {% tagList tags %}: Declare a variable namedtagsto store all related tags of the current article.
  • {% for item in tags %}: Loop through.tagsEach label in the array.
  • {{ item.Link }}: Output the link address of the current tag.
  • {{ item.Title }}Display the current tag name.

If you need to limit the number of tags displayed, you can uselimitparameters, for example{% tagList tags with limit="10" %}Only the first 10 tags will be displayed.

Integrate tags into the article detail page

Now, we will integrate the abovetagListtag code snippet into the template of the article detail page. Assuming we have already integrated it through the template.archiveDetailThe tag has retrieved other detailed information about the article, and we can choose a suitable position (such as below the article title, above the content, or at the bottom of the article) to display these tags.

The following is an example of an integration:

<article>
    <h1>{% archiveDetail with name="Title" %}</h1>

    <div class="article-meta">
        <!-- 其他文章元信息,如分类、发布时间、浏览量等 -->
        <a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a>
        <span>发布于:{% archiveDetail with name="CreatedTime" format="2006-01-02" %}</span>
        <span>阅读量:{% archiveDetail with name="Views" %}</span>
    </div>

    <div class="article-tags">
        <strong>标签:</strong>
        {% tagList tags %}
            {% for item in tags %}
                <a href="{{ item.Link }}" class="tag-link">{{ item.Title }}</a>
            {% endfor %}
        {% else %}
            <!-- 如果文章没有标签,可以显示一个提示 -->
            <span>暂无标签</span>
        {% endtagList %}
    </div>

    <div class="article-content">
        {%- archiveDetail articleContent with name="Content" %}
        {{ articleContent|safe }}
    </div>

    <!-- 其他详情内容,如上一篇、下一篇、相关文章等 -->
</article>

In this example, we willtagListplace the code in adivInside the container, and added the text prompt 'Label:'. For the aesthetic and readability of the page, you can use the CSS style of the website totag-linkAdd the corresponding styles, such as background color, border, padding, etc., to make the label stand out prominently.

By following these steps, the article detail page can dynamically display all associated Tag tags, greatly enriching the link depth of the article content, and also providing users with a diverse way to explore content.

Frequently Asked Questions (FAQ)

1. Why did I add a tag in the article detail page and there are no tags displayed on the page?tagList标签后,页面上却没有任何标签显示?

First, make sure that the template file you are editing is the actual template used for the current article detail page.You can check the "Document Template" field in the article editing interface on the backend to confirm if a custom template is used.Next, check if the article has really been added with the Tag tag.On the article editing page, find the "Tag label" section, make sure you have associated at least one tag with the article.If the article does indeed have tags but still does not display, please check the template code in thetagListandforDoes the loop syntax completely correct, including variable names, label names, etc.Finally, clear the system cache of AnQiCMS and try clearing the browser cache and refreshing the page.

2. How can I limit each article detail page to display a maximum of 5 Tag tags?

You can do this bytagListthe tag withlimitThe parameter is used to limit the number of displays. For example, if you want to display only the first 5 tags, you can modify the code as follows:

{% tagList tags with limit="5" %}
    {% for item in tags %}
        <a href="{{ item.Link }}" class="tag-link">{{ item.Title }}</a>
    {% endfor %}
{% else %}
    <span>暂无标签</span>
{% endtagList %}

This, even if the article is associated with 10 tags, the page will only display the first 5 associated tags.

3. What is the difference between Tag labels and article categories in AnQiCMS? How should I choose to use them?

In AnQiCMS, Tag tags and article categories are used to organize content, but they have different purposes and usages.

  • Article Category (Category): Typically represents the hierarchical structure of content with clear hierarchical relationships.An article generally belongs to only one main category, the category structure helps users understand the overall content architecture of the website, and allows for content filtering from large to small.Categories are often used in SEO to build clear URL structures and website hierarchies.
  • Tag label (Tag)It focuses more on describing the keywords or themes of the article, which are usually without hierarchical relationships, and an article can be associated with multiple unrelated tags.Tags are more like a 'non-structured' keyword association, which is convenient for users to quickly find related content through a specific topic, even if these contents may belong to different categories.In SEO, tags can enrich the keyword density of a page and create more internal links, enhancing relevance.

When choosing to use, consider the organization logic of the content: if the content has an obvious hierarchy and belonging relationship, it is more appropriate to use classification; if the content can be described from multiple dimensions and these dimensions are not suitable for constructing a hierarchy, then Tag labels will be a better choice, which can act as a supplement to classification and provide more granular content association.

Related articles

How to get all the top-level category lists and display them on the page?

## A Safe CMS: How to obtain and display all top-level category lists on a website page As a website operator, I am well aware of the importance of a clear website structure for user experience and search engine optimization (SEO).Category navigation is one of the core elements of website content organization, it not only guides users to quickly find the information they need, but also helps search engines better understand the hierarchy of website content.AnQiCMS (AnQiCMS) provides a直观 and powerful template tag system, allowing website operators to easily manage and display the classification structure of the website.

2025-11-06

How to display the detailed information (name, description, image) of a category on the category page?

As an experienced CMS website operation personnel of an enterprise, I am well aware of the core position of the classification page in the website structure and user experience.A well-designed, informative category page not only helps users quickly find the content they need, but also enhances the overall professionalism of the website through clear hierarchy and attractive visual elements, and is also crucial for search engine optimization (SEO).Today, I will elaborate on how to effectively configure and display the detailed information of category pages in Anqi CMS, including their names, descriptions, and associated images.### Enhance User Experience and SEO

2025-11-06

How to get the title and link of the previous and next articles of the current article?

As an experienced website operator familiar with AnQi CMS, I am well aware of the importance of article navigation in content management for improving user experience and optimizing website structure.When a reader is browsing an article meticulously crafted, if they can conveniently jump to the previous and next related or sequential articles, it not only extends the user's stay on the website, increases the page views, but also conveys a better internal link structure to search engines, thereby helping to improve the website's SEO performance.The AnQi CMS provides simple and powerful template tags

2025-11-06

How to dynamically generate the breadcrumb navigation path of the current page?

As an expert who deeply understands the operation of AnQiCMS, I know that a clear and easy-to-use navigation system is crucial for both website visitors and search engines.Breadcrumb Navigation is an effective tool that improves user experience and website SEO performance.It can directly display the user's current position in the website structure, helping them easily backtrack, and also provide clues for search engines about the website's hierarchical structure.

2025-11-06

How to customize the display of TDK (Title, Keywords, Description) content on a page?

As a senior AnQiCMS website operations personnel, I fully understand the core role of TDK (Title, Keywords, Description) in website search engine optimization (SEO).They are not only the key for search engines to understand the content of a page, but also important factors to attract users to click.In Anqi CMS, the configuration and custom display of TDK have high flexibility, which can meet the fine-grained optimization needs of different pages.

2025-11-06

How to use if-else logic in a template to control the display of content?

In Anqi CMS template creation, flexible control of content display is the key to improving user experience and meeting diverse business needs.As an experienced website operator, I am well aware of the importance of dynamic content presentation.The AnQi CMS adopts a syntax similar to the Django template engine, which allows content operators to implement conditional judgments in templates in a straightforward manner, thereby precisely controlling which content is visible to users at what time and place.The template syntax design of AnQi CMS makes it easy for developers and content operators to get started.

2025-11-06

How to traverse an array or list and output each item on the page?

In AnQi CMS template development, effectively traversing and outputting arrays or lists is a core skill for building dynamic and rich content pages.As a senior security CMS operator, I know the importance of flexibly using template tags for content presentation.The Anqi CMS adopts a syntax similar to the Django template engine, making content looping and conditional judgments intuitive and powerful.

2025-11-06

How to format a timestamp into a readable date and time string?

As an experienced CMS website operation staff member, I fully understand that the details of content presentation are crucial for user experience.The accurate and clear display of time information not only helps users quickly understand the publication or update time of the content, but also indirectly affects the professionalism and credibility of the website.In Anqi CMS, we have a highly efficient and flexible mechanism that can convert timestamp data stored in the background into user-friendly date and time strings.### Timestamp formatting feature in AnQi CMS In AnQi CMS, date and time data are usually stored internally in the form of timestamps

2025-11-06