How to get and display the Tag list of articles in the front-end template of AnQiCMS?

Calendar 👁️ 54

AnQiCMS as an efficient and flexible content management system provides a rich set of features to help operators manage and display website content.Among other things, the Tag label function of the article is an important factor in optimizing content organization, improving user experience and SEO effects.Understand how to obtain and display these tags in front-end templates, which is crucial for building a website with comprehensive features.

Manage tags in the AnQiCMS background

Before delving into the front-end template, let's briefly review how tags work in the AnQiCMS backend. AnQiCMS provides users with an intuitive tag management interface.

InContent ManagementPart, whether it isPublish documentOredit documentsYou can find the "Tag Tag" field. Here, you can add one or more tags to the article, you can choose existing tags, or you can directly input a new tag and press Enter to create it.These tags are like keywords for the content, which can associate articles with related topics.

Furthermore,Content ManagementThere is also a special one belowDocument TagFunction, you can view, edit, and delete all the tags created here, even set custom URLs, SEO titles, and descriptions for them, which is very helpful for the SEO optimization of the tab page.

Through these background operations, we have prepared rich tag data for the front-end display.

Understand AnQiCMS template basics

The AnQiCMS template engine syntax is similar to Django, which allows front-end developers to get started quickly. In the template files, we mainly interact with data in two ways:

  • Use{{变量}}Directly output the value of the variable.
  • Use{% 标签 %}and{% end标签 %}Execute logical judgments, loops, data queries, and other operations.

Understanding these basic syntax is the premise of successfully obtaining and displaying tags on the front-end.

Get and display the Tag label of the article on the article detail page

When a user browses a specific article, it is usually necessary to see the tags of the article in order to quickly understand the theme of the article or jump to more content under the related tags.In the AnQiCMS article detail template, it is very direct to obtain and display the tags of the current article.

We can usetagListTag to get the tag list associated with the current article. This tag defaults to reading the article ID of the current page, so you do not need to specify it separatelyitemIdParameter.

Here is a simple code example demonstrating how to display tags on the article detail page:

<div class="article-tags">
    <strong>标签:</strong>
    {% tagList tags with limit="10" %} {# 获取当前文章的最多10个标签 #}
    {% for item in tags %}
    <a href="{{item.Link}}" class="tag-item">{{item.Title}}</a>
    {% endfor %}
    {% endtagList %}
</div>

In this code block,tagList tags with limit="10"Will assign up to 10 tags associated with the current article totagsthe variable. Subsequently, we use{% for item in tags %}Loop through these tags and through{{item.Link}}Get the link address of the tags,{{item.Title}}Get the tag name, so that a clickable tag list can be rendered on the front end.

Display the list of popular tags on the entire site (tag cloud)

In addition to displaying tags in individual articles, websites usually also need a "tag cloud" or "hot tags" area to concentrate on showing all the tags on the site, guiding users to discover more content.

To get the full site tag list, you also usetagListtags, but you need to specify explicitlyitemId="0", indicating that it is not associated with any specific article but to get all tags. You can also uselimitParameter controls the number of items displayed, such as displaying the top 20 tags.

Here is an example of code to retrieve and display the site's popular tags.

<div class="popular-tags">
    <h2>热门标签</h2>
    <ul>
        {% tagList allTags with itemId="0" limit="20" %} {# 获取全站的最多20个标签 #}
        {% for tag in allTags %}
        <li><a href="{{tag.Link}}" class="tag-link">{{tag.Title}}</a></li>
        {% endfor %}
        {% endtagList %}
    </ul>
</div>

Here we assign all tags toallTagsVariables, and display their names and links in a loop. You can add different styles or adjust the order of these tags according to your actual needs.

Create an independent tag list page (tag/index.html)

AnQiCMS allows you to create a dedicated tag list page, for example/tagsThe path used to display all tags of the website and support pagination. According to the AnQiCMS template convention, such pages are usually namedtag/index.html.

In such a page,tagListLabel combinationtype="page"Parameters can implement pagination display of the tag list. At the same time, cooperate withpaginationTags can generate a complete pagination navigation

{# 假设这是 tag/index.html 模板文件 #}
<h1>所有标签</h1>

<div class="tag-list-pagination">
    {% tagList tags with type="page" limit="20" %} {# 每页显示20个标签,并启用分页 #}
    <ul class="tag-grid">
    {% for item in tags %}
    <li>
        <a href="{{item.Link}}" class="tag-card">
            <h3>{{item.Title}}</h3>
            <p>{{item.Description | truncatechars:100}}</p> {# 显示标签描述,并截取前100字 #}
        </a>
    </li>
    {% empty %}
    <li>
        暂无任何标签。
    </li>
    {% endfor %}
    </ul>
    {% endtagList %}

    {# 分页导航 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            {# 首页 #}
            <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
            {# 上一页 #}
            {% if pages.PrevPage %}
            <a class="page-link" href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
            {% endif %}
            {# 中间多页 #}
            {% for item in pages.Pages %}
            <a class="page-link {% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
            {% endfor %}
            {# 下一页 #}
            {% if pages.NextPage %}
            <a class="page-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
            {% endif %}
            {# 尾页 #}
            <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        {% endpagination %}
    </div>
</div>

Display the list of articles under a specific tag (tag/list.html)

When a user clicks on a specific tag, the website usually jumps to a page that displays all the

Related articles

How to implement keyword search and filtering display on article list or search result pages?

How to allow visitors to quickly find the content they need among the vast amount of information on our website is undoubtedly the key to improving user experience and the effectiveness of content marketing.AnQiCMS (AnQiCMS) knows this and therefore provides a powerful and flexible mechanism to help us easily implement keyword search and content filtering functions on article lists or search result pages.The implementation of this feature mainly revolves around the core template tags of AnQi CMS, allowing us to transform the content of the background management into a user-friendly interactive interface through the exquisite design of the frontend template.###

2025-11-07

How to add watermarks to images on the AnQiCMS website to protect original content?

In today's increasingly rich digital content, protecting the copyright of original works is particularly important, especially for visual content such as images.When your website publishes a large number of carefully crafted images, if they are not protected, it is easy for others to copy and repost them arbitrarily, which not only infringes on your labor results but also weakens the uniqueness of the content.Adding a watermark to an image is a simple and effective means of copyright protection, which can clearly assert ownership of the content without affecting the beauty of the image, effectively deterring unauthorized use.Anqi CMS as a highly efficient

2025-11-07

How to display the filing number and copyright information at the bottom of the website in AnQiCMS?

During the operation of a website, whether it is to meet the requirements of laws and regulations or to enhance the professionalism and user trust of the website, clearly displaying the filing number and copyright information at the bottom of the website is an important aspect.AnQiCMS as an efficient content management system provides a very flexible and intuitive way to configure and display these key information. Next, we will introduce step by step how to set and display the filing number and copyright information at the bottom of the AnQiCMS website.### The first step: Fill in the filing number and copyright information in the background First

2025-11-07

How to display the name and link of the current article's category in a frontend template?

In website content operation, the classification information of articles not only helps users quickly understand the content attribution, but also is the key to improving the website navigation experience and search engine optimization (SEO) effect.For friends who use AnQiCMS to build websites, it is a very practical and basic requirement to accurately display the name of the category to which each article belongs and provide a link.AnQiCMS provides powerful and flexible template tags, allowing us to easily achieve this function.### Skillfully Utilize `archiveDetail`

2025-11-07

How to display a custom page template independently on a specific page (such as About Us)?

Hello! When using AnQi CMS to build a website, we often encounter such needs: some specific pages, such as 'About Us', 'Contact Us', or some special topic pages, need to have a completely different layout and design from other pages on the website.Luckyly, AnQi CMS provides a very flexible solution for this, allowing you to easily specify independent custom templates for these pages.AnQi CMS with its efficient features based on the Go language and support for Django template engine syntax, brings great convenience and customizability to content display

2025-11-07

How to determine if a variable is empty in AnQiCMS template and display default content?

In website content operation, data integrity and the elegance of display are crucial.We often encounter such situations: some fields of data may be missing for various reasons, such as an article may not have an illustration, a product may not have a detailed description, or a custom field may not be filled in.If the template code does not perform the corresponding null value judgment, it may result in blank pages on the page, affecting the aesthetics, or may even cause template rendering errors, affecting the user experience.AnQiCMS with its efficient architecture based on the Go language and similar to Django

2025-11-07

How to implement safe output of HTML tags in article content to avoid XSS attacks?

In AnQiCMS, we not only pursue efficient and flexible content management, but also regard website security as a core element.In daily content creation and template development, a seemingly simple HTML tag output actually hides potential security risks, the most common of which is cross-site scripting (XSS) attack.Understanding how AnQiCMS processes HTML output and mastering security practices is crucial for building a robust and reliable website.How does AnQiCMS handle HTML content output?In AnQiCMS template rendering mechanism

2025-11-07

How to extract the article summary and add an ellipsis in AnQiCMS template?

In website operation, how to make the article list page both beautiful and informative is a common concern.Generally, we do not display the full content of the article on the list page, but instead use a short 'abstract' to attract readers to click.To maintain the cleanliness and professionalism of the page, these summaries often need to be automatically truncated when exceeding a certain length and appended with an elegant ellipsis.AnQiCMS is a powerful content management system that provides flexible tools in the template to help us meet this need.Below, we will discuss in detail how to use AnQiCMS

2025-11-07