How to retrieve and display the document list under a specified Tag in AnQi CMS?

Calendar 👁️ 63

AnQiCMS (AnQiCMS) offers great convenience to website operators with its flexible content management and powerful template engine.In daily content operations, we often need to aggregate and display lists of associated documents based on specific tags (Tag), such as "Hot Topics", "Technical Tips", or "Product Reviews" and the like.This not only helps users quickly find the content they are interested in, but also effectively improves the internal link structure of the website, which is very beneficial for SEO.

This article will delve into how to retrieve and display the document list under the specified tag in AnQiCMS, helping you better utilize the tag feature and optimize content presentation.

Understand the tag function in AnQiCMS

In AnQiCMS, tags are a very practical way to classify content, different from traditional hierarchical classification, and more focused on the keyword association of content.You can add one or more tags to content models such as articles, products, etc. to achieve multi-dimensional content classification.For example, an article about 'website construction' can be tagged with 'SEO', 'user experience', 'front-end development', and so on.

In the AnQiCMS backend, you can create, edit, and manage tags under the 'Content Management' section of the 'Document Tags' module.Each label has a unique ID and alias, which is useful when calling the front-end template.

Core tags:tagDataListapplication

To retrieve and display the document list under a specified tag, AnQiCMS provides a special template tag:tagDataList. This tag is our core tool, which can flexibly retrieve related documents according to the tag ID.

1. Display the document list under the current tag on the tag details page.

When a user visits a specific tag detail page (for example你的域名/tag/SEO), we usually want to display all documents tagged with the 'SEO' tag directly on this page. At this point,tagDataListTags are not requiredtagIdIt intelligently identifies the tag ID of the current page and retrieves the associated document.

This is a basic template code example, used to display the document list and implement pagination on the tag detail page:

{# 获取当前标签的详细信息,例如标签标题和描述 #}
{% tagDetail currentTag with name="Title" %}
{% tagDetail tagDescription with name="Description" %}

<h2>标签: {{ currentTag }}</h2>
{% if tagDescription %}
<p>{{ tagDescription }}</p>
{% endif %}

<div class="tag-documents">
    {# 使用 tagDataList 获取当前标签下的文档列表,并开启分页功能 #}
    {% tagDataList archives with type="page" limit="10" %}
        {% for item in archives %}
        <article class="document-item">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>{{ item.Description|truncatechars:150 }}</p> {# 截取前150个字符作为简介 #}
            <div class="meta-info">
                <span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>浏览量: {{ item.Views }}</span>
                {# 如果需要显示文档所属分类,可以这样获取 #}
                {% categoryDetail docCategory with name="Title" id=item.CategoryId %}
                {% if docCategory %}
                <span>分类: <a href="{% categoryDetail with name='Link' id=item.CategoryId %}">{{ docCategory }}</a></span>
                {% endif %}
            </div>
            {% if item.Thumb %}
            <div class="document-thumb">
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
            </div>
            {% endif %}
        </article>
        {% empty %}
        <p>抱歉,当前标签下暂无文档。</p>
        {% endfor %}
    {% endtagDataList %}

    {# 添加分页导航 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            <a class="first-page {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{ pages.FirstPage.Link }}">首页</a>
            {% if pages.PrevPage %}
            <a class="prev-page" href="{{ pages.PrevPage.Link }}">上一页</a>
            {% endif %}
            {% for pageItem in pages.Pages %}
            <a class="page-number {% if pageItem.IsCurrent %}active{% endif %}" href="{{ pageItem.Link }}">{{ pageItem.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}
            <a class="next-page" href="{{ pages.NextPage.Link }}">下一页</a>
            {% endif %}
            <a class="last-page {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{ pages.LastPage.Link }}">尾页</a>
        {% endpagination %}
    </div>
</div>

In this example:

  • We first usetagDetailGet the current tag title and description to display on the page.
  • tagDataList archives with type="page" limit="10"It will fetch the documents under the current tag, display 10 per page, and assign the document list toarchivesVariable.type="page"is the key to enable pagination.
  • for item in archivesLoop through each document,item.Link/item.Title/item.Description/item.CreatedTime/item.Views/item.Thumbetc. are common fields of the document.
  • stampToDateTags used to format the document's publish time.
  • categoryDetailTags used to get the name and link of the category the document belongs to.
  • Finally,pagination pages with show="5"Used to render pagination navigation,show="5"indicating that up to 5 page buttons are displayed.

2. Call the document list by the specified tag ID on other pages

If you want to display selected documents under a specific tag on the homepage, sidebar, article detail page, or any other page on your website, you need to specify the tag ID and the number of documents you want to display.

Assuming you have a label called "Hot Recommendations" with an ID of5You want to display 3 documents under this label on the homepage.

<div class="featured-tags-section">
    <h3>热门推荐</h3>
    <ul>
        {# 使用 tagDataList 获取标签ID为5的文档,限制显示3篇 #}
        {% tagDataList hotPicks with tagId="5" limit="3" %}
            {% for doc in hotPicks %}
            <li>
                <a href="{{ doc.Link }}">{{ doc.Title }}</a>
                <p class="summary">{{ doc.Description|truncatechars:80 }}</p>
            </li>
            {% empty %}
            <li>暂无热门推荐文档。</li>
            {% endfor %}
        {% endtagDataList %}
    </ul>
</div>

Here:

  • tagId="5"It precisely specifies which label's documents to retrieve.
  • limit="3"Controlled the number of displayed documents.
  • hotPicksIs the custom variable name you set for this document list.

Flexible and versatile: CombinetagListDisplay tag cloud and content

Sometimes, you may want to display the popular tags or all tags on the website first, and then allow users to click on the tags to jump to the corresponding tag detail page and view the documents under it. This can be done bytagListTag implementation.

`twig

<h3>探索更多话题</h3>

Related articles

How to set and display a custom template on a single page of AnQi CMS?

AnQi CMS, with its powerful flexibility and ease of use, has become a helpful assistant for many content operators.Especially in terms of content display, it provides us with rich customization space.For those web pages that require unique layouts or specific functions, such as "About Us", "Contact Us", or a special event landing page, we often hope that they can have a completely different visual style from ordinary articles or list pages.Aqii CMS provides a very convenient way for us to set exclusive custom templates for these single-page websites

2025-11-08

How to display the child category list of a specified category in Anqi CMS

The way website content is organized is crucial for user experience and information retrieval efficiency.A clear classification structure not only helps visitors quickly find the information they need, but also effectively enhances the professionalism and user retention rate of the website.In AnQiCMS (AnQiCMS), the flexible template tag system makes it very convenient to display the subcategory list of a specified category.### Core Tool: The Use of `categoryList` Tag To display the child category list of a specified category in Anqi CMS, we mainly use the `categoryList` tag

2025-11-08

How does Anqi CMS implement the scheduled release of website content, so that it automatically displays at a specified time?

In content operations, efficiency and strategic thinking are the key to success.AnQiCMS (AnQiCMS) is well-versed in this field and offers a practical feature - scheduled content publishing, allowing website managers to accurately schedule the content release time, thus achieving automated operation and effectively enhancing the spread of content and website activity. ### Scheduling Posting: The Automation Tool for Content Operations Imagine that your website needs to publish industry news at a fixed time every morning, or plan a series of promotional articles in advance for specific holidays or marketing events. If relying on manual release by humans

2025-11-08

How to display the website logo and filing information in the AnQi CMS front-end template?

In website operation, Logo and filing information are not only the core of brand recognition, but also an important link for establishing user trust and complying with regulations.AnQi CMS took these key elements into consideration from the very beginning, providing intuitive settings and flexible template calling methods, allowing website operators to easily display this information on the front end.### Understanding AnqiCMS template mechanism Before delving into how to display the logo and filing information, it is very helpful to briefly understand the AnqiCMS frontend template mechanism.

2025-11-08

How to display and manage the website message form of AnQi CMS and customize fields?

The website message form is an important link between users and the website, it not only helps us collect valuable opinions and suggestions, but also lays the foundation for various interactive functions such as user consultation and service reservation.AnQi CMS is well-versed in this, providing website operators with a straightforward, efficient, and highly customizable feedback form solution, making it exceptionally simple to manage and customize form fields.### Easily build the frontend presentation of the message form In Anqi CMS, to display the message form on the website page, you do not need to write complex backend logic, just insert the specific tags in the template file

2025-11-08

How to add and display friendship links on the Anqi CMS website?

In website operation, friendship links play an indispensable role.They not only help to improve the search engine ranking (SEO) of a website, but also bring potential traffic and improve the user experience, allowing visitors to get more information through related websites.AnQiCMS (AnQiCMS) understands this and therefore provides an intuitive and convenient friend link management feature, allowing you to easily add, manage, and display these important external connections.This article will introduce in detail how to add friend links in the Anqi CMS background, as well as how to flexibly display them on the website's front-end template

2025-11-08

How does the comment function of AnQi CMS display comment lists and reply levels?

AnQiCMS (AnQiCMS) as an efficient and flexible content management system, provides rich content display capabilities while also offering a comprehensive comment function for user interaction.Understand how to effectively display a comment list, especially in handling multi-level replies, which is crucial for enhancing the user engagement and content depth of a website. ### AnQiCMS Comment Function Implementation Basics Commenting functionality is an important part of website content interaction in AnQiCMS.The system is not only built-in with support for comments on articles, products, and other content

2025-11-08

How can conditional judgments (if/else) be used in the AnQi CMS template to control content display?

AnQiCMS template development skills: flexibly use conditional judgment (if/else) to control content display In website content operation, we often need to display or hide specific content blocks based on different conditions, or to differentiate the display based on different data states. AnQiCMS (AnQiCMS) powerful template engine provides us with flexible conditional judgment capabilities, through the clever use of `if/else` statements, you can easily achieve the fine-grained control of content, making your website more dynamic and user-friendly.

2025-11-08