How to display the Tag tag list and corresponding documents of articles in AnQiCMS template?

Calendar 81

In Anqi CMS, the organization and presentation of content are diverse, among which the Tag label feature of articles provides users with flexible keyword association and content discovery paths.No matter if you want to display related tags on the article detail page or create a page that aggregates content with specific tags, Anqi CMS provides intuitive and powerful template tags to meet these needs.

Next, we will discuss how to effectively display the Tag list of articles and their corresponding documents in the AnQiCMS template.

I. Display of article Tag label list

First, let's take a look at how to display the Tag tag of the article in the template.This usually has two main scenarios: one is to display the tags belonging to a single article page;Secondly, on the website's sidebar, footer, or a dedicated tag index page, it displays a list of all site or popular tags.

1. Display the current article tags on the article detail page

When a user reads a specific article, you may want to display tags associated with the article at the bottom or sidebar.This helps the reader understand the theme of the article and quickly jump to other articles with the same tag.

AnQi CMS providestagListTags to obtain the list of article tags. In the template of the article detail page (usually{模型table}/detail.html),tagListThe tag will automatically identify the ID of the current article.

You can use it like this:

<div class="article-tags">
    <strong>标签:</strong>
    {% tagList tags %}
        {% for item in tags %}
            <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
        {% endfor %}
    {% endtagList %}
</div>

In this code block:

  • We use{% tagList tags %}To get all the tags of the current article and assign the result totagsVariable.
  • Then, through{% for item in tags %}Iterate through each tag.
  • item.LinkIt will automatically generate a URL pointing to the tag detail page.
  • item.TitleIt displays the name of the tag.

This will elegantly display all related tags on your article detail page, each tag is clickable for easy exploration of more content.

2. Display popular/all tags in the website sidebar or dedicated page

If you want to display a certain number of tags on non-article detail pages of the website, such as the homepage sidebar, blog list page, or an independent "tag cloud" page, you can use it againtagListLabels, and make use of themlimitparameter to control the number of displayed items.

For example, display the latest 10 labels:

<div class="hot-tags-widget">
    <h3>热门标签</h3>
    <ul>
        {% tagList tags with limit="10" %}
            {% for item in tags %}
                <li><a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a></li>
            {% endfor %}
        {% endtagList %}
    </ul>
</div>

here,limit="10"It will ensure that only the latest 10 labels are displayed. If you want to display all labels, you can omit itlimitParameter, or set it to a sufficiently large number. It should be noted that if it is not called on the article detail page, and you want to display the tags of the entire site rather than the tags of a specific article, you must ensureitemIdThe parameter is not explicitly set or set toitemId="0"to avoid the tag list being affected by the current page content ID.

II. Display of document list under Tag tag

When a user clicks on a tag, it usually jumps to a tag detail page, which aggregates all articles associated with this tag. This page is usually corresponding to the template directory under AnQi CMS.tag/list.htmlortag/index.html.

We need to use a specific tag to display a list of documents on this page,tagDataListwhich is used to fetch articles under the specified tag. In the tag details page,tagDataListThe tag will automatically identify the tag ID of the current page (tagId).

Here is an example of a list of documents under the tag with pagination functionality:

{# 假设这是 tag/list.html 或 tag/index.html 模板 #}
<h1>标签:{% tagDetail with name="Title" %}</h1>
<p>{% tagDetail with name="Description" %}</p>

<div class="tag-documents">
    {% tagDataList archives with type="page" limit="10" %}
        {% for item in archives %}
            <div class="document-item">
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {% if item.Thumb %}
                        <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="document-thumb">
                    {% endif %}
                    <h2>{{ item.Title }}</h2>
                </a>
                <p class="document-description">{{ item.Description }}</p>
                <div class="document-meta">
                    <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    <span>阅读量:{{ item.Views }}</span>
                    {% if item.CategoryId %}
                        <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                    {% endif %}
                </div>
            </div>
        {% empty %}
            <p>该标签下暂时没有任何文章。</p>
        {% endfor %}
    {% endtagDataList %}

    {# 分页导航 #}
    <div class="pagination-container">
        {% pagination pages with show="5" %}
            <ul>
                {% if pages.FirstPage %}
                    <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a></li>
                {% endif %}
                {% if pages.PrevPage %}
                    <li><a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a></li>
                {% endif %}
                {% for pageItem in pages.Pages %}
                    <li class="{% if pageItem.IsCurrent %}active{% endif %}"><a href="{{ pageItem.Link }}">{{ pageItem.Name }}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>
                {% endif %}
                {% if pages.LastPage %}
                    <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a></li>
                {% endif %}
            </ul>
        {% endpagination %}
    </div>
</div>

In this code block:

  • <h1>标签:{% tagDetail with name="Title" %}</h1>Used to display the name of the current tag,tagDetailThe tag will automatically obtain the Tag ID of the current page.
  • {% tagDataList archives with type="page" limit="10" %}Get the list of articles associated with the current tag.type="page"Enables pagination,limit="10"Then set each page to display 10 articles.
  • {% for item in archives %}Traverse each article.item.Link/item.Title/item.Description/item.ThumbCorrespond to the link, title, introduction and thumbnail of the article.
  • stampToDate(item.CreatedTime, "2006-01-02")Is a practical function used to format timestamps into readable dates.
  • {% categoryDetail with name="Title" id=item.CategoryId %}Used to display the category name of the article in the article list.
  • {% pagination pages with show="5" %}Tags are used to generate pagination navigation,show="5"Controls the maximum number of page buttons displayed, up to 5.

In this way, after the user clicks on any tag, they can clearly see all related articles and can easily browse through the pages.

Summary

The Anqi CMS tag system provides great flexibility for content management and user experience. ThroughtagListandtagDataListTwo core tags, you can easily display article tags at various locations on the website and build a comprehensive tag aggregation page.This kind of tagged content organization not only helps with the website's SEO, but also enhances the fun and efficiency of users exploring content on your site.


Frequently Asked Questions (FAQ)

1. How to create and manage Tag tags in the Anqi CMS backend?

You can find "Content Management" in the left menu of the Anqi CMS backend and then click on "Document Tag".In here, you can add tags, set names, index letters, custom URLs, SEO titles, keywords, and descriptions for each tag.The creation of tags is very flexible, not dependent on specific categories or models, and can be associated across content models, making them more flexible in content organization than categories.

2. What is the difference between Tag tags and article categories? How should I choose to use them?

Article categories (Category) are typically used for organizing content in a hierarchical structure, with clear parent-child relationships, and each article must belong to a category.It helps users and search engines understand the overall structure of a website.For example, a "news" category can have subcategories such as "domestic news" and "international news".

Tag labels are more focused on keyword association and thematic aggregation, it does not have a strict hierarchical relationship, an article can have multiple tags.Tags can be considered as the "horizontal" association of an article. For example, an article about "AnQi CMS tutorial" can be classified under the "Tutorial" category, and it can also be tagged with "CMS", "Website Building", "Go Language", and other tags.

Choose to use it when you need clear structure and hierarchy, please use categories;If your content requires flexible keyword association and multi-dimensional aggregation to facilitate users in discovering related topics, then tags are a better choice.Both are usually combined to achieve **content organization effects.

3. How to customize the URL structure of the Tag tag page to optimize SEO?

AnQi CMS supports pseudo-static rules, allowing you to customize

Related articles

How to implement content collection and batch import in AnQiCMS and control its final display effect?

In the current era of explosive digital content, efficient content management and refined presentation are the goals pursued by every website operator.For those who need to frequently update industry information, aggregate a large amount of materials, or manage multiple content sites, manually entering content is undoubtedly a time-consuming and labor-intensive task that is prone to errors.幸运的是,AnQiCMS provides us with powerful content collection and batch import functions, and with flexible template systems, we can easily achieve automated content updates while accurately controlling the final presentation of content.

2025-11-07

How do AnQiCMS's static cache and SEO optimization features work together to improve content loading speed and display quality?

In today's fast-paced digital world, whether a website can successfully attract and retain users, the speed of content loading and visibility in search engines are two crucial factors.We all hope that our websites can present quickly at the moment when users click on the link and stand out when users search for relevant information.

2025-11-07

How to display exclusive content accessible to different user groups (such as VIP) in AnQiCMS?

In content management and operation, providing customized exclusive content for different user groups is an important strategy to enhance user value and achieve content monetization.AnQiCMS as a flexible and efficient content management system fully considers this requirement, and through its powerful user group management and content reading level functions, it helps us easily achieve this goal. ### Core Mechanism: User Groups and Content Reading Levels In AnQiCMS, the implementation of exclusive content mainly depends on two core functions: **User Group Management** and **Content Reading Levels**.In simple terms

2025-11-07

How to configure anti-crawling interference code and image watermark in AnQiCMS to protect the display of original content?

Today, with the increasing amount of digital content, the value of original content is becoming increasingly prominent, but it also faces unprecedented risks of misuse.Whether it is a carefully written article or high-quality illustrations, they may be inadvertently collected and copied by others, infringing on the rights of the original creators.Anqi CMS is well-versed in this, for this reason it has built-in powerful anti-crawling interference codes and image watermarking functions, aiming to provide a solid protective barrier for your original content.Today, let's delve deeper into how to configure these features in AnQiCMS so that your hard work is not easily 'stolen'.

2025-11-07

How to implement pagination and like function in AnQiCMS comment list?

The Anqi CMS plays a crucial role in content operation, where user interaction is an important factor in enhancing website activity. The comment function, along with its配套 pagination display and like function, is undoubtedly the key to achieving this goal.Benefiting from AnQiCMS's flexible template engine and rich built-in tags, we can relatively easily add these features to the articles or products of the website. ### 1.The basic enablement and configuration of the comment function Firstly, ensure that the website's comment function is enabled.

2025-11-07

How to call and display friend links in AnQiCMS templates?

Friendship links, as part of the website content ecosystem, not only help to improve search engine rankings and optimize website weight, but also provide users with more navigation to related resources.In AnQiCMS, managing and displaying friend links is a direct and flexible task, even if you do not have a deep programming background, you can easily achieve it. ### Backend Management: Easily Configure Friend Links In the AnQiCMS backend management interface, you will find the friend link settings under the "Function Management" menu.

2025-11-07

How to implement pagination for document lists in AnQiCMS and support custom page number quantities?

AnQiCMS document list pagination and custom page number settings: Make your content management more efficient Imagine, when your website content becomes rich, with thousands of articles, products, or news lists neatly arranged, if you cannot organize and display them effectively, users may feel at a loss.A good pagination mechanism not only improves user experience and helps visitors quickly find the information they need, but is also an important aspect of SEO optimization.

2025-11-07

How to use conditional judgment (if/else) tags to control the display logic of content in AnQiCMS templates?

In the development and maintenance of website templates, we often encounter the need to display or hide different content based on specific conditions.This dynamic content display logic is crucial for improving user experience, realizing personalized functions, and optimizing the website structure.AnQiCMS (AnQiCMS) is a powerful content management system that provides a flexible template engine, among which the condition judgment (`if/else`) tags are the core tools to achieve this goal.

2025-11-07