How to use the AnQiCMS `tagList` tag to display a list of related tags and their links with the article?

Calendar 👁️ 77

Manage and display content in AnQiCMS, the Tag (Tag) is a very practical feature.It can not only help you better organize the content of the article, but also provide users with more flexible navigation methods, and is very beneficial for search engine optimization (SEO).When a reader is browsing an article, if they can see a list of related tags and click on these tags to find more similar content, it will undoubtedly greatly enhance the user experience and the PV (Page Views) of the website.

Today, let's delve into how to make use of it in AnQiCMS.tagListLabels, easily display the list of tags and their links related to the current article on the article page.

The value of the tag and AnQiCMS tag management

In AnQiCMS, you can find the 'Document Tag' feature under the 'Content Management' module in the backend.When publishing or editing an article, the system provides an intuitive interface for adding multiple tags to the article.These tags can be keywords, topics, or any words you think can summarize the content of the article.

The tag management design of AnQiCMS is very flexible, the same tag can be associated with articles under different content models.Each tag can have an independent name, index letter, custom URL, and SEO description, making the tag itself an important part of the website's content system, which can be better indexed and understood by search engines.

IntroductiontagListTag: The core of article tag display

Display the list of tags associated with the current article on the article page, we mainly use the built-in tags of AnQiCMStagListThis tag is specifically used to retrieve and display document tag information.

tagListTags usually appear in pairs, formatted as follows:

{% tagList 变量名 with 参数 %}
    {# 循环处理标签数据的代码 #}
{% endtagList %}

Among them,变量名Is the temporary variable name you define for the tag list obtained, for examplearticleTags. Inside the tag, you can useforLoop to iterate over this variable to display the details of each tag one by one.

Practical demonstration: Display the tag list on the article detail page.

Suppose you want to display all the tags associated with each article at the bottom of the article, and make these tags clickable so that they can jump to the topic page of the tag. In the AnQiCMS article detail template, it is usually{模型table}/detail.htmlYou can write code like this in Chinese:

{# 在文章详情页(例如:archive/detail.html)的合适位置 #}
<div class="article-tags-section">
    <strong>相关标签:</strong>
    {% tagList currentArticleTags %} {# 默认会自动获取当前文档的ID来显示相关标签 #}
        {% for item in currentArticleTags %}
            <a href="{{ item.Link }}" 
               class="tag-link" 
               title="查看更多关于 {{ item.Title }} 的内容">{{ item.Title }}</a>{% if not forloop.Last %}, {% endif %}
        {% empty %}
            <span>暂无相关标签。</span>
        {% endfor %}
    {% endtagList %}
</div>

In this code block:

  • {% tagList currentArticleTags %}We define a variable namedcurrentArticleTagsVariable to store the tag list obtained. When unspecifieditemIdparameters,tagListIt will intelligently get the ID of the current page article and display all associated tags.
  • {% for item in currentArticleTags %}:TraversecurrentArticleTagsarray,itemThe variable represents a specific label object in each loop.
  • {{ item.Link }}This is the link address of the tag. Clicking it will lead the user to the aggregation page of the tag, displaying all articles with this tag.
  • {{ item.Title }}This is the display name of the tag.
  • {% if not forloop.Last %}, {% endif %}This is a little trick used to add a comma after each tag name, but not the last one, making the display more natural.
  • {% empty %} ... {% endfor %}If the current article is not associated with any tags, this part of the content will be displayed, prompting the user 'No related tags.' to avoid leaving the page blank.

Flexible Application: ExploretagListAdditional parameters

tagListThe tag also provides some parameters that allow you to finely control the display of the tag.

  1. itemId: Specify or get the site-wide tag

    • Default behavior (without)itemId)As shown in the example above, on the article detail page, it will automatically retrieve the tags of the current article.
    • Specify article IDIf you want to display tags for a specific ID article instead of the current page, you can use it like this:
      
      {# 显示ID为123的文章的所有标签 #}
      {% tagList specificArticleTags with itemId="123" %}
          {% for item in specificArticleTags %}
              <a href="{{ item.Link }}">{{ item.Title }}</a>
          {% endfor %}
      {% endtagList %}
      
    • Get all site tagsIf you want to display all tags in the sidebar, footer, or independent tabs (such astag/index.html) you can setitemId="0".
      
      {# 在侧边栏或页脚显示全站热门标签 #}
      <div class="site-tag-cloud">
          <h3>热门标签</h3>
          {% tagList allSiteTags with itemId="0" limit="30" %} {# itemId="0" 表示获取所有标签,不与当前文章关联 #}
              {% for item in allSiteTags %}
                  <a href="{{ item.Link }}">{{ item.Title }}</a>
              {% endfor %}
          {% endtagList %}
      </div>
      
  2. limitControl the number of displayed items.This parameter can limit the number of tags displayed. For example, if you only want to display the top 10 tags, you can do it like this:

    {# 显示当前文章的前5个标签 #}
    {% tagList limitedTags with limit="5" %}
        {% for item in limitedTags %}
            <a href="{{ item.Link }}">{{ item.Title }}</a>
        {% endfor %}
    {% endtagList %}
    

    limitit also supportsoffsetpatterns, such aslimit="2,10"It indicates the second one.

Related articles

Does the AnQiCMS 'Full Site Content Replacement' feature affect the display of frontend content immediately?

In content operations, sometimes we need to make unified adjustments to a large amount of content on the website, whether it is updating expired information, correcting brand names, or optimizing internal links, manual individual modification is undoubtedly a huge workload.AnQiCMS provides a powerful feature named 'Full Site Content Replacement', aimed at helping us efficiently solve such problems.However, many users may have a question when using this feature: Will the content on the website's front-end be immediately synchronized and updated after the full-site content replacement operation, so that visitors can see the latest modifications?

2025-11-09

How to integrate and display the custom contact information on the AnQiCMS frontend page, such as WhatsApp links?

On AnQiCMS, we often need to allow visitors to contact us in the most convenient way, and WhatsApp, due to its widespread usage, has become the preferred contact tool for many businesses and individuals.Luckyly, AnQiCMS was designed with flexibility in content and functionality in mind, allowing you to easily customize the contact information in the backend and display it on the front page of the website.This article will thoroughly introduce you to how to add and manage custom contact methods like WhatsApp in the AnQiCMS background

2025-11-09

How to call and display the subcategory list or associated article list under a specified category in AnQiCMS?

When using AnQiCMS for website content management, we often need to display information according to a specific content organization method.How can you flexibly call and display the list of subcategories under a specified category, or the list of articles associated with that category, which is a scenario many users will encounter.AnQiCMS's powerful template engine and rich tag functions make it intuitive and efficient to meet these requirements.

2025-11-09

How to display the 'Previous' and 'Next' document links and titles of the current article in AnQiCMS template?

The effective organization and convenient navigation of website content is the key to improving user experience and extending visit duration.When a visitor is immersed in your article, if they can seamlessly jump to related or adjacent content, it will undoubtedly greatly enhance the continuity of their browsing.AnQiCMS as a fully functional content management system provides intuitive and powerful template tags, helping us easily implement the display of 'Previous' and 'Next' document links and titles on article detail pages.

2025-11-09

How does AnQiCMS ensure that uploaded JPG/PNG images are automatically converted to WebP format to optimize front-end loading and display?

In today's digital age, website loading speed is crucial for user experience and search engine rankings.Among them, image files are an important part of web content, and their loading efficiency often directly affects overall performance.Traditional JPG and PNG image formats are widely used, but they are usually less efficient in file size than the emerging WebP format.How can AnQiCMS (AnQiCMS) automatically implement this optimization during image upload to enhance the front-end loading display of the website?

2025-11-09

How to set up AnQiCMS to automatically compress large images and specify display width to improve page loading performance?

In today's digital age, the loading speed of a website directly affects user experience, search engine rankings, and even business conversion rates.Images, as an important part of web content, are often one of the key factors affecting page performance, in terms of their size and loading methods.If there are a large number of unoptimized large images on the website, even if the content is精彩, it may still deter visitors.

2025-11-09

How to configure the thumbnail generation processing method (such as cropping, scaling by the longest side) for AnQiCMS to optimize display effects?

In content operation, images play a crucial role, and thumbnails, as the 'face' of the content, directly affect the first impression and click intention of users.A clear, beautiful, and fast-loading thumbnail that not only enhances the overall visual experience of the website but also effectively optimizes the search engine crawling and ranking, truly a win-win situation.How do we finely tune the thumbnail generation processing method in AnQiCMS to achieve **display effects?Why is thumbnail configuration so important?

2025-11-09

How to control whether the website name suffix is attached to the home page title in the AnQiCMS home page TDK settings?

The website's homepage title (Title) is one of the key elements of Search Engine Optimization (SEO), which not only directly affects the willingness of users to click on the website in search results but also carries the important responsibility of brand information delivery.In AnQiCMS (AnQi Content Management System), we often encounter a problem: how to flexibly control the home page title so that it can display the core content while optionally adding or not adding the website name as a suffix?AnQiCMS provides an intuitive and efficient setting method.

2025-11-09