How to loop through and display the article tag list in AnQiCMS templates?

Calendar 👁️ 69

In Anqi CMS, article tags are not only a tool for organizing content and improving user experience, but also an important element for optimizing search engine crawling and ranking (SEO).They can help visitors quickly find relevant content and also help search engines better understand the website structure.How can you flexibly iterate and display these article tag lists in AnQiCMS templates?This is actually simpler than you imagine, the powerful template tag system of AnQiCMS makes everything very intuitive.

AnQiCMS uses a syntax similar to the Django template engine, which makes it easy for content developers to get started. When handling article tags, we mainly use a core tag:tagList.

Deep understandingtagListTag

tagListTags are specifically used to retrieve and display article tag data.It allows you to retrieve tags based on different needs, such as getting the tags of the current article, specifying the tags of a specific article, or even the tag list of the entire site.

To usetagListLabel, you need to wrap it like this in a{% tagList ... %}and{% endtagList %}structure, and use it to{% for ... %}loop through the label data obtained.

Let's take a look attagListCommon parameters of labels and what information they can provide:

  • itemId: This parameter is very critical.
    • If you use it on the article detail pagetagListand do not specifyitemId, it will default to getting the tags of the article currently being viewed.
    • If you want to get the tags of a specific article (for example, on the article list page, showing the tags of each article), you can pass the article ID throughitemId="文章ID"to pass the article ID.
    • If you want to get tags for the entire site without targeting a specific article, you canitemIdis set to"0".
  • limit: This parameter helps you control the number of tags displayed, such aslimit="5"Indicates that up to 5 tags can be displayed. This is very useful when displaying popular tags or limiting the number of tags on the article detail page.
  • type: Attag-archiveTag.mdmentionedtype="page"Can be used to display tag lists in pagination, mainly intag/index.htmlThis label is used in the home page template. Usually, it is not necessary to set this parameter for displaying tags in articles.
  • siteId: If you use the multi-site management feature of AnQiCMS and need to call data from other sites, you can specify the site ID through this parameter.In most cases, there is no need to fill in.

In{% for ... %}In the loop, each label item is usually used as a variable (for example, we name it)item), it will contain the following useful fields:

  • {{item.Title}}: The display name of the tag, such as "Website Operation", "SEO Tips", etc.
  • {{item.Link}}: The URL link corresponding to the tag, clicking on it will usually jump to the article list page under the tag.
  • {{item.Id}}: Unique ID of the label.
  • {{item.Description}}: Description information of the tag (if set in the background).

Practice Exercise: Label Display in Common Scenarios

Next, let's see how to apply in the template through several common scenarios.tagList.

Scenario one: Display the current article tags on the article detail page

This is a common requirement. When a user reads a specific article, we hope to display all the tags associated with the article at the bottom or in the sidebar.

You can add the following code in the template file corresponding to the article detail page (usuallyarchive/detail.htmlor a custom article template)

<div class="article-tags">
    <h4>文章标签:</h4>
    {% tagList tags %} {# 不指定 itemId,默认获取当前文章的标签 #}
        {% for item in tags %}
            <a href="{{item.Link}}" class="tag-item">{{item.Title}}</a>
        {% endfor %}
    {% endtagList %}
    {% empty %} {# 如果文章没有标签,可以显示一个提示 #}
        <span>暂无标签</span>
    {% endtagList %}
</div>

This code will iterate over all the tags of the current article and generate clickable links for each tag. You can enhance their display with CSS styles such as.tag-item) to beautify their appearance.

Scenario two: Display tags for each article on the article list page

On the article list page (such as the category list pagecategory/list.htmlor the homepageindex/index.htmlWe may wish to briefly display some related tags below the title or introduction of each article. This requires combiningarchiveListTags andtagListtags for nested use.

{% archiveList archives with type="page" limit="10" %} {# 外部循环:获取文章列表 #}
    {% for archive in archives %}
        <article class="post-item">
            <h3><a href="{{archive.Link}}">{{archive.Title}}</a></h3>
            <p class="post-description">{{archive.Description}}</p>
            <div class="post-meta">
                <span>发布日期:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
                <span class="tags-list">
                    {% tagList tags with itemId=archive.Id limit="3" %} {# 内部循环:获取当前文章的标签,并限制显示3个 #}
                        {% for tag in tags %}
                            <a href="{{tag.Link}}" class="tag-small">{{tag.Title}}</a>
                        {% endfor %}
                    {% empty %}
                        <span></span>
                    {% endtagList %}
                </span>
            </div>
        </article>
    {% endfor %}

    {# 如果需要,这里可以添加分页代码 {% pagination pages with show="5" %}...{% endpagination %} #}
{% endarchiveList %}

Here, itemId=archive.Idis crucial, it ensures thattagListAlways get itCurrent article being traversedtag. Throughlimit="3"We limit each article to display only 3 tags to keep the list page tidy.

Scenario 3: Display the list of popular or latest tags on the entire site.

The website sidebar, footer, or dedicated tag archive page usually displays a hot tag cloud or the latest tag list.At this point, we do not care about the tags of specific articles, but we want to obtain global tag data.

<div class="sidebar-block">
    <h4>热门标签</h4>
    <div class="tag-cloud">
        {% tagList globalTags with itemId="0" limit="20" %} {# itemId="0" 获取全站标签,limit限制数量 #}
            {% for tag in globalTags %}
                <a href="{{tag.Link}}" class="global-tag">{{tag.Title}}</a>
            {% endfor %}
        {% endtagList %}
    </div>
</div>

By settingitemId="0",tagListYou will get the list of tags on the entire site. You can adjust them as neededlimitvalue, as well as assign them different sizes or colors through CSS to form a tag cloud effect.

Content operation and SEO tips

Displaying article tags reasonably in the template can not only improve the user experience of the website, but also have a positive impact on SEO:

  1. Strengthen internal linksEach tag link points to a related tag archive page, which provides more internal links for search engine crawlers, helping to improve the inclusion and weight distribution of website content.
  2. Improve content discovery: Users can quickly find related topics of interest through tags, increase page dwell time, and reduce bounce rates.
  3. **Clear theme

Related articles

How to call and display data from different sites in AnQiCMS multi-site management?

AnQiCMS (AnQiCMS) as an efficient and flexible content management system, its powerful multi-site management function is undoubtedly a highlight favored by many operators.When we hold multiple brand, multiple region, or multiple theme websites, we can manage them uniformly through a system and flexibly call and display data between different sites, which will greatly improve work efficiency and content integration.How can we implement the calling and display of data between different sites in the AnQiCMS multi-site environment?### Understanding the core of multi-site data calls

2025-11-07

How to display the unique field content according to a custom content model?

AnQi CMS with its powerful content management capabilities, especially the flexible content model, makes the organization of our website content simpler than ever before.When the standard content field cannot meet specific business needs, a custom content model and its unique fields emerge.How can you accurately call and display these unique custom field contents in the website front-end template?This article will detail the mysteries revealed for you. ### 1. Understanding the content model and custom fields of AnQi CMS One of the core strengths of AnQi CMS is its highly flexible content model

2025-11-07

How to generate and display breadcrumb navigation in the AnQiCMS template?

In website operation, a clear navigation structure is crucial for improving user experience and search engine optimization (SEO).Imagine if, when visitors delve deep into your website, there was a path guide to tell them 'You are here', wouldn't that make them feel at ease and convenient?This is the function of Breadcrumb Navigation.It is like breadcrumbs scattered in fairy tales, helping users easily backtrack in the website and understand the position of the current page in the overall website structure.

2025-11-07

How to display the friend link list on the AnQiCMS website?

Friend links are an indispensable part of website operation, as they not only promote communication and cooperation between websites, but also have a positive effect on SEO optimization.In AnQiCMS, displaying the friend link list is a simple and efficient process, allowing website administrators to easily provide visitors with more valuable external resources. ### Backend Management: Configure Your友情链接 Firstly, you need to configure the友情链接 in the backend of AnQiCMS in order to display it on the front page.

2025-11-07

How to implement multi-language content switching and display on AnQiCMS websites?

Under the wave of globalization, website multilingual support has become a necessary condition for enterprises to expand into the international market.AnQiCMS as an enterprise-level content management system, fully considers this requirement and provides a set of efficient and flexible solutions to help users easily switch and display multilingual content. ### AnQiCMS implementation logic for multilingual The core strategy of AnQiCMS for switching and displaying multilingual content is based on its powerful "multi-site management" function.

2025-11-07

How to implement pagination functionality and customize the number of page numbers displayed in AnQiCMS templates?

In a content management system, an effective pagination feature is crucial for improving user experience and the SEO performance of the website.When the amount of content on a website gradually increases, organizing and displaying the content list reasonably allows visitors to browse information more easily and helps search engines better crawl and index the page.AnQiCMS as an efficient content management system provides flexible and easy-to-use template tags, allowing you to easily implement pagination in the template and customize the display of page numbers as needed.To implement pagination in the AnQiCMS template, it mainly involves two core steps

2025-11-07

How does AnQiCMS ensure that uploaded images are automatically converted to WebP format to optimize loading speed?

In today's fast-paced digital world, website loading speed directly affects user experience and search engine rankings.Especially images, they are often the main culprits in slowing down website speed.Large image files not only consume more server bandwidth, but also extend the page rendering time, leading to visitor loss. 幸运的是,AnQiCMS understands this and provides us with an elegant solution through intelligent image processing: automatically converting uploaded images to WebP format to optimize website loading speed. WebP is a modern image format developed by Google

2025-11-07

How to display the contact information of the website, such as phone, address, email, in AnQiCMS templates?

The contact information of the website, like a business card, is an important channel for visitors to understand and trust the website.Whether it is to hope that customers call to consult or to make it convenient for them to communicate through email, or to guide them to the physical store, clear and accurate contact information is indispensable.In AnQiCMS, displaying this information is a very intuitive and flexible thing, which allows us to not only manage uniformly but also display at different positions on the website according to our needs.

2025-11-07