How to display all the Tag tags belonging to the current article in AnQiCMS template?

Calendar 👁️ 69

Display article tags flexibly in the AnQiCMS template

In website content operation, tags are a highly effective content organization method.They can not only help users find relevant content faster and improve the browsing experience of the website, but also have an indispensable positive effect on search engine optimization (SEO).AnQiCMS as a feature-rich enterprise-level content management system naturally also provides powerful tag management and call functions, allowing us to easily display all tags associated with the current article on the article detail page.

This article will guide you on how to flexibly and efficiently display the tags of the current article in the AnQiCMS template, making your content more organized and discoverable.

The role and value of tags

Imagine, when readers finish reading an article, if they can immediately see the keyword tags related to the article, they are likely to click on these tags and explore more content on the same topic.This not only prolonged the user's stay on the website, but also brought more page views to the website.

In terms of the website itself, the tag system has multiple values:

  • Enhancing content relevance:Link articles with similar topics or keywords through tags to form a content network.
  • Enhancing user experience:Provide users with multi-dimensional navigation methods to facilitate their discovery of content based on interest.
  • Optimize SEO: The tab itself can be a valuable landing page, helping search engines better understand the structure and theme of the website content, and increase the coverage of keywords.AnQiCMS has especially added the Tag label feature for articles and products in version v2.1.0, and built-in advanced SEO tools, fully reflecting its emphasis on tags in SEO.

In AnQiCMS background management label

Before starting template development, make sure your article has been tagged. The AnQiCMS backend operation is very intuitive:

  1. Publish or edit articlesWhen you enter the article editing interface, you will find an input box named "Tag Tag" in the sidebar or at the bottom (the specific location may vary depending on the model configuration).
  2. Add Tag: You can enter a new label name here, then press Enter to confirm, and it will automatically be converted into a label.Or, you can also click the input box, and the system will pop up a list of existing tags for you to choose from.
  3. Independence of TagsThe AnQiCMS tag is universally used across the entire site, without distinguishing between article models or product models. This means you can use the same tags for different types of content, further strengthening the connection between content.

Make sure your article is associated with at least one tag so that we can see the actual effect in the frontend template.

How to call article tags in the template: core steps

AnQiCMS uses syntax similar to the Django template engine to make template creation very easy to pick up. To view the article details page, it is usuallyarchive/detail.htmlOr you can customize the article template) to display the tags of the current article, we need to use the AnQiCMS providedtagList.

tagListTags are used to retrieve the list of tags associated with the article. In the context of the article detail page, it will default to retrieving all tags of the current article.

Here is a basic code snippet that shows how to call and display tags in a template:

<div class="article-tags">
    <strong>标签:</strong>
    {% tagList currentArticleTags %}
        {% for tag in currentArticleTags %}
            <a href="{{ tag.Link }}" class="tag-item">{{ tag.Title }}</a>
        {% empty %}
            <span>这篇文章暂时还没有关联任何标签哦!</span>
        {% endfor %}
    {% endtagList %}
</div>

Let's go into a detailed explanation of this code:

  1. {% tagList currentArticleTags %}: This is the calltagListThe label begins. We will assign the list of labels we obtain to a custom variablecurrentArticleTags. You can name this variable according to your preference, just make it easy to understand.
  2. {% for tag in currentArticleTags %}: Due tocurrentArticleTagsis a list containing multiple label objects, we need to useforloop to iterate through it, each loop will assign a label object totagVariable.
  3. {{ tag.Link }}and{{ tag.Title }}: inside the loop,tagAn object includes all the properties of a label. The most commonly used isLink(The link address of the tab) andTitle(The display name of the label). By{{ }}Braces syntax, we can output these values to HTML.
  4. {% empty %}: This is a very practical feature. If the current article has no tags,forthe loop will execute.emptyBlock content, rather than nothing displayed, which can provide a friendly prompt to the user.
  5. {% endfor %}and{% endtagList %}: These are the end tags corresponding to the labels, ensuring the integrity of the template structure.

Place this code in your article detail template, and it will automatically fetch and display all the tags associated with the current article. Don't forget to.article-tagsand.tag-itemAdd some CSS styles to make the label look more beautiful.

Further customize and optimize.

AnQiCMS'tagListThe label also provides some parameters to allow you to more flexibly control the display of the label:

  • Limit the display quantity (limit)If you want to display only the first few tags of the article, you can uselimitParameter.

    {% tagList currentArticleTags with limit="5" %}
        {# ... 循环代码 ... #}
    {% endtagList %}
    

    Even if the article is associated with ten tags, only the first five will be displayed.

  • To get the tags of a specific article (itemId): Although the default behavior on the article detail page is to fetch the current article tags, if you want to fetchotherthe tags of the article, you can useitemIdparameters and pass in the ID of the article.

    {# 假设你想获取ID为100的文章的标签 #}
    {% tagList otherArticleTags with itemId="100" %}
        {# ... 循环代码 ... #}
    {% endtagList %}
    
  • Retrieve all site tags (itemId="0")Sometimes, you may need to display a list of all site tags in the sidebar or other areas (such as popular tag clouds). At this point, you canitemIdis set to0.

    {% tagList allSiteTags with itemId="0" limit="20" %}
        {# ... 循环代码 ... #}
    {% endtagList %}
    

    cooperatelimitParameters can easily build a tag cloud.

By using these flexible tags, you can create a diverse tag display effect according to the design and operation needs of the website in AnQiCMS, making your website content more organized and more favored by readers and search engines.

Summary

Displaying article tags in AnQiCMS is a simple and powerful feature. Through convenient tag management on the back end, combined with the front-end template intagListThe flexible use of tags, you can easily enhance the relevance of website content, improve user experience, and lay a solid foundation for SEO performance.Go ahead and try to add and display these practical tags in your AnQiCMS website!


Frequently Asked Questions (FAQ)

Q1: Why does the tag I added in the article background not display on the front page?

A1: Please check the following aspects:

1.

Related articles

How to get and display related article lists according to Tag ID in AnQiCMS template?

In a content management system, Tag (tag) plays an important role.They can not only help us flexibly organize content, but also associate articles with similar themes across different categories, and can effectively improve the website's internal link structure and user experience.When a user is interested in a specific topic, by clicking on a Tag, they can easily view all related articles.AnQiCMS provides a set of intuitive and powerful template tags that allow you to easily retrieve and display these related article lists based on Tag ID.

2025-11-07

How to automatically generate and display the content directory (ContentTitles) on the article detail page of AnQiCMS?

## How to automatically generate and display the content directory (ContentTitles) on the AnQiCMS article detail page??For long content, a clear table of contents (also known as "article outline" or "chapter navigation") can greatly enhance the reading experience of users.It not only helps readers quickly understand the structure of the article, but also allows them to directly jump to the chapters of interest, thereby improving the readability and user satisfaction of the content.

2025-11-07

How to implement lazy loading of image content in AnQiCMS templates to optimize performance?

In the digital age, the speed of website access has become one of the key indicators for measuring user experience and search engine rankings.Images are an important part of web page content and often also a major factor affecting page loading speed.When a page contains a large number of high-definition images, the browser needs to load all image resources before rendering the page, which undoubtedly greatly increases the user's waiting time.This problem was solved by the emergence of lazy loading (Lazy Loading) technology.The core idea of lazy loading images is to delay loading images that are not within the current viewport (i.e., the visible area of the user's current screen)

2025-11-07

How to display custom field content (such as author, source) in AnQiCMS templates?

AnQiCMS with its flexible content model and powerful template tag system provides great convenience for personalized display of website content.In website operations, we often need to add some information outside of standard fields for articles, products, or other content, such as the author of the article, source of content, product batch number, or specific SEO information.This non-standardized information, AnQiCMS calls it 'custom fields', they can make your website content more professional, detailed, and meet specific business needs.

2025-11-07

How to dynamically display the Title, Keywords, and Description information of the website homepage in AnQiCMS template?

In website operation, the Title (title), Keywords (keywords), and Description (description) of the homepage are the first impression given to users on the search engine results page (SERP) and are also the key for search engines to understand the core content of the website.They not only affect the website's search engine optimization (SEO) effect, but also directly relate to whether users will click to enter your website.AnQiCMS as a feature-rich enterprise-level content management system provides a straightforward and powerful way to manage these important SEO elements. Next

2025-11-07

How to judge whether a variable is empty in AnQiCMS template and set a default display value?

During the development of website templates, it is often encountered that the variable value may be empty.If not properly handled, the front-end page may appear with unattractive blank areas, even displaying some default placeholders (such as `nil` or `null`), which undoubtedly affects user experience and the professionalism of the website.AnQiCMS (AnQiCMS) provides a powerful and flexible template engine that can help us elegantly determine whether variables are empty and set appropriate default display values.

2025-11-07

How to truncate a long string (such as an article summary) to a specified length and display an ellipsis in the AnQiCMS template?

In website content operation, the display length of article abstracts or introductions often needs careful control.Long content can affect the layout and user experience of a page, while a concise summary with an ellipsis can effectively guide users to click and read more details.AnQiCMS provides flexible template tags and filters, allowing us to easily implement this feature.

2025-11-07

How to remove specific HTML tags from an HTML string in the AnQiCMS template (such as `<i>`, `<span>`)?

In AnQiCMS template development, we often encounter content coming from rich text editors, or imported from external sources, which may contain some HTML tags that we do not want to display at specific locations.For example, in the summary section of the article list, we may only want to display plain text, or we may need to remove specific tags such as `<i>`, `<span>`, etc. to maintain the consistency of the page style.

2025-11-07