How to display a list of all related articles under a specific Tag tag?

Calendar 👁️ 65

In Anqi CMS, tags (Tag) are an important tool for organizing content, enhancing user experience, and optimizing search engine performance.It can link articles from different categories but with related themes, making it easier for visitors to find content they are interested in.When you need to display a list of all associated articles under a specific Tag label, Anq CMS provides a concise and powerful template tag to help you achieve this goal.

Understand the Core:tagDataListTag

To display the list of articles under a specific Tag label, we mainly use the built-in Anqi CMStagDataListLabel. This label is specifically used to retrieve article data associated with a certain Tag. It is flexible and can be used to filter, sort, and paginate the display of articles according to your needs.

a basictagDataListThe usage of the tag is generally like this:

{% tagDataList archives with tagId="1" %}
    {# 在这里循环显示文章内容 #}
{% endtagDataList %}

Among them,archivesIt is a variable name you define to store the list of articles retrieved.tagId="1"It is crucial, it tells the system that you want to retrieve the articles associated with the Tag with ID 1.

How to get the ID of a specific Tag?

In actual operation, you may need to explicitly know the Tag ID to calltagDataList. There are two common scenarios:

  1. In a dedicated Tag list page (for example:template/your_template_name/tag/list.html)If you are editing a page specifically designed to display articles under a certain Tag, such as a page that users are redirected to after clicking on a tag in the Tag cloud, then Anqi CMS will usually automatically identify the Tag ID of the current page. In this case, you can even omit it.tagIdparameter,tagDataListAutomatically fetches the data of the current Tag. In addition, you can also throughtagDetailTags to get the details of the current Tag, such as the title and description, which is very useful for building page titles and SEO descriptions.

    {# 假设当前是Tag列表页,系统会自动识别当前Tag的ID #}
    {% tagDetail currentTag with name="Title" %}
    <h1>{{ currentTag }} 标签下的文章</h1>
    
    {% tagDetail tagDescription with name="Description" %}
    <p>{{ tagDescription }}</p>
    
    {% tagDataList archives with type="page" limit="10" %}
        {# 接下来是文章列表和分页代码 #}
    {% endtagDataList %}
    
  2. Display articles with a specific Tag on any pageIf you want to display articles under a fixed tag on the homepage, a category page, or an article detail page, you need to specify manuallytagId. This ID can be found on the "Content Management" -> "Document Tags" page in the AnQi CMS backend. Click on the corresponding Tag to edit, and you will see its ID.

    For example, assuming you know the ID of the tag "latest news" is 5, you can call it like this:

    <h2>最新动态</h2>
    {% tagDataList archives with tagId="5" limit="5" order="id desc" %}
        {% for item in archives %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {% empty %}
            <li>暂无相关文章。</li>
        {% endfor %}
    {% endtagDataList %}
    

Build an article list

tagDataListTags support various parameters, allowing you to control the display of articles more finely:

  • tagId: Specify the ID of the Tag. For example,tagId="1".
  • moduleIdIf your website has multiple content models (such as article models, product models), you can use this parameter to specify only displaying articles under specific models. For examplemoduleId="1"Indicates that only the data of the article model is displayed.
  • limit: Controls the number of articles displayed. For examplelimit="10"It will display 10 articles.
  • order: Specify the sorting method of the article, common ones include:
    • order="id desc": Sort by article ID in reverse order (usually the most recently published)
    • order="views desc": Sort by views in descending order (popular articles)
    • order="sort desc": Sort by custom sorting in the background
  • type: Defines list type.type="list"Will directly list the specified number of articles;type="page"Will enable pagination,配合paginationlabel usage

In{% for item in archives %}the loop,itemThe variable contains detailed information about each article, you can call it as needed:

  • item.Title: Article title
  • item.Link: Article link
  • item.Description: Article Summary
  • item.Thumb: Article Thumbnail
  • item.Views: Article views
  • item.CreatedTime: Article publish time (to be usedstampToDateFilter formatting

For example, display the article title, thumbnail, and publish time:

{% tagDataList archives with tagId="您要查询的TagID" moduleId="1" limit="10" order="id desc" %}
    {% for item in archives %}
        <div class="article-item">
            {% if item.Thumb %}
                <a href="{{ item.Link }}"><img src="{{ item.Thumb }}" alt="{{ item.Title }}"></a>
            {% endif %}
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>{{ item.Description | truncatechars:100 }}</p>
            <span class="publish-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% empty %}
        <p>当前Tag下暂无文章。</p>
    {% endfor %}
{% endtagDataList %}

Introduce pagination feature

If there are many articles under the Tag, enabling pagination can effectively improve loading speed and user experience. You need totagDataListsettype="page", then combinepaginationCreate pagination links with tags.

{% tagDataList articles with tagId="您的TagID" moduleId="1" type="page" limit="10" order="id desc" %}
    {# 循环显示文章的for循环和内容 #}
    {% for item in articles %}
        <div class="article-item">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>{{ item.Description }}</p>
            <span class="publish-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% empty %}
        <p>当前Tag下没有找到任何文章。</p>
    {% endfor %}

    {# 分页代码 #}
    <div class="pagination-area">
        {% pagination pages with show="5" %}
            {# 首页链接 #}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
            {# 上一页链接 #}
            {% if pages.PrevPage %}
                <a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a>
            {% endif %}
            {# 中间页码 #}
            {% for page_item in pages.Pages %}
                <a class="{% if page_item.IsCurrent %}active{% endif %}" href="{{ page_item.Link }}">{{ page_item.Name }}</a>
            {% endfor %}
            {# 下一页链接 #}
            {% if pages.NextPage %}
                <a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a>
            {% endif %}
            {# 尾页链接 #}
            <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
        {% endpagination %}
    </div>
{% endtagDataList %}

Complete Tag article list page example

This is a typicaltag/list.htmltemplate file structure, which combines Tag details, article list, and pagination functions, providing a comprehensive content display for your Tag page:

”`twig {% extends ‘base.html’ %} {# Inherit your base template #}

{% block head_meta %}

{# 获取当前Tag的SEO信息,并显示在页面的meta标签中 #}
<title>{% tdk with name="Title" siteName=true %}</title>
<meta name="keywords" content="{% tdk with name="Keywords" %}">
<meta name="description" content="{% tdk with name="Description" %}">
{% tdk canonical with name="CanonicalUrl" %}
{% if canonical %}<link rel="canonical" href="{{ canonical }}" />{% endif %}

{% endblock %}

{% block content %}

{# 获取当前Tag的详细信息,用于页面标题和简介 #}
{% tagDetail currentTag with name="Title" %}
<h1>标签:{{ current

Related articles

How to display all used Tag tags on the website or only display Tag tags related to the current article in AnQiCMS?

When building website content, tags play an important role. They can not only help you better organize information and improve the discoverability of content, but also optimize the user experience, making it easier for visitors to find the content they are interested in.For a content management system, flexibly displaying and managing these tags is one of its core values.AnQiCMS provides powerful functions in this aspect, allowing you to easily control the display of tags on your website according to your actual needs.### Add and manage Tag tags On AnQiCMS backend

2025-11-08

How to create and display single-page content such as “About Us” and “Contact Us”?

In website operation, single-page content like "About Us", "Contact Us", and the like are windows to showcase the corporate image, core values, or provide key information to visitors.They usually carry stable, independent and infrequent updated content, which is crucial for building trust and providing service access.AnQiCMS provides very convenient and powerful functions for managing and displaying these single-page applications, allowing you to easily create and customize them.### Part 1: Create Your Single Page Content Creating a single page in AnQiCMS is an intuitive and efficient process

2025-11-08

How to display the top-level category list of a specific content model on the homepage or sidebar?

In AnQi CMS, managing website content, we sometimes need to clearly display the top-level category list of a specific content model at key positions such as the homepage or sidebar.This not only effectively guides visitors to browse the website content and improve user experience, but is also an important aspect of website content architecture optimization and search engine friendliness.Using AnQiCMS's flexible template system and powerful tag features, it is direct and efficient to meet this requirement. ### Understanding the Core: Content Model and Classification The core of content management in Anqi CMS lies in the "content model".You can create different content models based on business requirements

2025-11-08

How can I build and display a multi-level nested category navigation menu?

Building and displaying multi-level nested category navigation menus in Anqi CMS is an important aspect of website content organization and user experience optimization.A well-designed, hierarchical navigation not only helps visitors quickly find the information they need, but also provides clear website structure signals to search engines, thereby improving SEO effectiveness. AnQi CMS is an enterprise-level content management system developed in Go language, with flexible content models and powerful template tags, making it very intuitive and efficient to implement multi-level classification navigation.Next, we will explore how to step by step build such navigation

2025-11-08

How can I optimize the URL structure of the AnQiCMS website to improve search engine friendliness?

During the operation of a website, a good URL structure, like a clear map, can not only help users intuitively understand the content of the page, but also guide search engines to more efficiently crawl and understand your website.AnQiCMS was designed with SEO needs in mind from the beginning, built-in powerful URL management functions, allowing us to easily create a search engine-friendly website structure.Understanding why search engine friendly URLs are important Before delving into the specific features of AnQiCMS, let's talk briefly about it

2025-11-08

Can I customize the URL paths for articles, categories, and single pages, and how do I do it?

In website operation, a clear and meaningful URL path not only enhances user experience but is also one of the key factors in search engine optimization (SEO).AnqiCMS as an efficient content management system fully considers this need and provides the function of flexible customization of articles, categories, and single-page URL paths.How does AnqiCMS support custom URL?AnqiCMS has built-in powerful pseudo-static functions, which allows your website pages to be dynamically generated even if their content is dynamic

2025-11-08

How to dynamically set the Title, Keywords, and Description (TDK) information for each page?

In website operation, each page's Title (title), Keywords (keywords), and Description (description) information, which we commonly call TDK, plays a vital role.They are not only the key for search engines to understand page content, but also important factors to attract users to click.In AnQiCMS, dynamically setting this information for each page is much more efficient and flexible than you might imagine.How to make TDK settings efficient and convenient in AnQiCMS

2025-11-08

Does AnQiCMS support generating and displaying canonical URLs (Canonical URL) to avoid duplicate content issues?

In website operation, duplicate content is undoubtedly a major challenge in Search Engine Optimization (SEO).Search engines tend to provide users with the most relevant and authoritative content. When they find the same or highly similar content under multiple URLs, they may feel confused, not knowing which version to index, which may scatter the ranking signals of the page and even affect the overall reputation of the website.For this issue, AnQiCMS provides a clear and practical solution, explicitly supporting the generation and display of canonical URLs.This means as a website operator

2025-11-08