How to display the list of article tags (Tag) and the related articles under each Tag?

Calendar 👁️ 62

The AnqiCMS provides very flexible and powerful tools for content organization, among which tags (Tag) are a very intuitive and efficient tool.By using labels reasonably, it can not only help us better manage website content, but also significantly improve user experience and search engine optimization (SEO) effectiveness.Next, let's take a look at how to display the article tag list in Anqi CMS, as well as the related articles under each tag.

Step 1: Manage and create tags in the background

Before using tags, first ensure that our website content has been properly tagged.In the Anqi CMS backend, we can find the 'Document Tag' feature through 'Content Management'.In here, you can conveniently add, edit, or delete tags.Each tag can be set to its name, index letter, custom URL, as well as the title, keywords, and description used for SEO.

When you publish or edit a document, simply enter or select existing tags in the "Tag label" field to associate the document with the corresponding tags.The tag design of Anqi CMS is very flexible, it does not differentiate between content models and categories, which means you can associate documents of different types (such as articles, products) and documents under different categories through the same tag, realizing the integration of cross-content themes.

Step 2: Display the entire site tag list

We often need to display all the popular or important tags on the homepage, sidebar, or a special "tag cloud" page of the website to guide users to discover more interesting content.

To achieve this, we can use the built-in Anqi CMStagListtag. This tag can help us get the tag data and then display it through the template loop.

Suppose we want to display up to 20 tags in a certain area of the website, and these tags link to their respective article list pages, we can write the template code like this:

<div class="tag-list-section">
    <h3>热门标签</h3>
    <ul>
        {% tagList tags with limit="20" itemId="0" %}
        {% for item in tags %}
        <li>
            <a href="{{item.Link}}" title="{{item.Title}}">{{item.Title}}</a>
        </li>
        {% endfor %}
        {% empty %}
        <li>暂时没有可显示的标签。</li>
        {% endendtagList %}
    </ul>
</div>

here,tagListAfter the tagstagsThis is the variable name we give to the tag list data.limit="20"It limits the number of displayed tags.itemId="0"It is a critical parameter that tells the system we want to retrieve all tags instead of tags associated with a specific document.

If this list is part of the website "tag homepage" (usually corresponding totag/index.htmla template), and we want the tag itself to support pagination, then we cantagListadd in thetype="page"the parameter and cooperatepaginationthe tag to use:

<div class="all-tags-page">
    <h1>全部标签</h1>
    {% tagList tags with type="page" limit="50" itemId="0" %}
    <ul>
        {% for item in tags %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
        {% endfor %}
    </ul>
    {% endtagList %}

    {# 分页代码 #}
    <div class="pagination">
        {% pagination pages with show="5" %}
            {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
            {% for pageItem in pages.Pages %}
            <a class="{% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
            {% endfor %}
            {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
        {% endpagination %}
    </div>
</div>

Step 3: Display the associated tags of a single article

When a user reads a specific article, we usually want to show the details page of the article (such asarchive/detail.htmlTemplate) Displays tags directly related to the article. This helps users quickly understand the article's theme and find related content.

In this scenario, we still usetagListLabel, but no need to specifyitemIdParameters. The system will automatically identify that the current page is an article detail page and retrieve the tags associated with the current article:

<article>
    <!-- 文章内容区域 -->
    <div class="article-content">
        <!-- ... 文章标题、正文等 ... -->
    </div>

    <div class="article-tags">
        <strong>相关标签:</strong>
        {% tagList tags %}
        {% for item in tags %}
        <a href="{{item.Link}}" class="tag-item" title="{{item.Title}}">{{item.Title}}</a>
        {% endfor %}
        {% empty %}
        <span>暂无标签</span>
        {% endendtagList %}
    </div>

    <!-- ... 上一篇/下一篇、相关文章等 ... -->
</article>

In this way, each article will display the tags associated with it below, and clicking will jump to the article list under the tag.

Step 4: Display the article list under a specific tag

The ultimate purpose of the tag is to aggregate related articles under a certain theme to form a content special page.When the user clicks on a tag, they should be able to see a list of all articles with that tag.This usually correspondstag/list.htmlTemplate.

To implement the article list under a specific label, we need to usetagDataListthe label. This label is specifically used to retrieve all documents under a specified label.

The following is intag/list.htmlTemplate showing the example code for displaying a list of articles with specific tags:

`twig

{# 获取当前标签的详细信息,例如标题 #}
{% tagDetail currentTag with name="Title" %}
<h1>标签:{{currentTag}}</h1>

<div class="tag-description">
    {# 获取并显示标签的描述信息 #}
    {% tagDetail tagDesc with name="Description" %}
    {% if tagDesc %}
    <p>{{tagDesc}}</p>
    {% endif %}
</div>

<ul class="article-list">
    {% tagDataList archives with type="page" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}" class="

Related articles

How does AnQi CMS display detailed content of a single page (such as About Us, Contact Information)?

In website operation, pages such as "About Us", "Contact Information", and "Privacy Policy" play a crucial role. They are the basis for visitors to show corporate information and establish trust.AnQiCMS as an efficient content management system provides a very flexible and intuitive way to create and display the detailed content of these single pages.

2025-11-08

How to dynamically display the name, description, and link of content categories in a template?

In website operation, clearly displaying content categories not only helps users quickly find the information they need, but is also a key link to improve website usability and search engine optimization (SEO).AnQiCMS (AnQiCMS) with its flexible template engine allows us to easily dynamically call and display the names, descriptions, and links of various content categories in website templates.Today, let's delve deeper into how to achieve this goal in templates, making your website content more vivid and efficient.### Understanding Content Classification in AnQi CMS In the AnQi CMS backend management system

2025-11-08

How to retrieve and display custom parameters of content models such as articles, products, etc. in a template?

In Anqi CMS, when managing website content, we often encounter the need to display specific information in addition to standard fields such as title and text.For example, when operating an e-commerce website, in addition to the name and description of the product, it may also be necessary to display 'material', 'origin', 'warranty period', and so on;Or you may be running an information blog, where articles may need to display 'author source', 'publisher' and other information.The flexible content model design of AnQi CMS is to meet this diverse content display requirement.Today, let's delve deeper into the topic

2025-11-08

How does Anqi CMS handle images in content to optimize loading speed and display quality (WebP, compression)?

In the content of the website, images play a crucial role, they can enrich the visual effects and convey complex information.However, unoptimized images are often the culprit for slow website loading and poor user experience.As content operators, we fully understand the value of image optimization in improving website performance and user retention.AnQiCMS provides a series of powerful and intelligent functions in image processing, aiming to help us easily achieve a balance between image loading speed and display quality.

2025-11-08

How to implement pagination control for content list display in Anqi CMS?

In website operation, how to efficiently display and manage a large amount of content while ensuring a smooth browsing experience is a challenge that every webmaster needs to face.AnQiCMS provides an intuitive and powerful control capability for pagination display of content lists, allowing you to easily achieve an orderly presentation and efficient navigation of content.To implement the pagination display of content lists, we mainly use two core tags in Anqi CMS templates: content list tags (such as `archiveList`, `tagDataList`

2025-11-08

How to display custom contact information (such as phone, address, social media) in the template?

The contact information on the website is the key bridge between you and the visitors for establishing communication and trust.Whether seeking services, consulting products, or simply learning more information, clearly and accurately displaying contact information is crucial for improving user experience.AnQi CMS is an efficient and convenient content management system that provides an intuitive backend management interface and flexible template calling function, allowing you to easily manage these information and seamlessly present them on every corner of the website.This article will guide you in setting up these key contact information in Anqi CMS

2025-11-08

How to define and display different banner images for different parts of the website in AnQiCMS?

In website operation, banner images are important visual elements that attract visitor attention and convey key information.They can not only enhance the overall aesthetics of the website, but also guide users to browse specific content or participate in promotional activities.AnQiCMS provides a flexible mechanism that allows you to customize and display unique Banner images for different parts of the website, such as the homepage, various thematic category pages, or independent content pages, thereby achieving more refined visual marketing.

2025-11-08

How to use the structured data (JSON-LD) feature of Anqi CMS to enhance the search engine results display?

In today's highly competitive online environment, making a website's content stand out in search engine results pages (SERP) and attract more target users is the goal of every website operator.In addition to keyword optimization, high-quality content, and a good user experience, using structured data (JSON-LD) to "tell" search engines exactly what your content is becoming a key factor in improving website visibility and obtaining rich search results (Rich Snippets).

2025-11-08