How to display the Tag list of articles in AnQiCMS template and generate links for each Tag?

Calendar 👁️ 66

AnQiCMS template article tag list and link generation and display

As an operator who deeply understands the operation of AnQiCMS and has a profound understanding of content operation, I know that article tags play a core role in enhancing the discoverability of content, optimizing user experience, and strengthening website SEO.Labels can not only help readers quickly find related content, but also provide more rich semantic information for search engines.This article will detail how to efficiently display the tag list of articles in the AnQiCMS template and generate clickable links for each tag.

Understanding AnQiCMS tag function

AnQiCMS provides a user-friendly tag management system.In the "Content Management" module in the background, you can find the "Document Tag" feature.Here, you can create, edit, manage all tags, and configure names, index letters, custom URLs, SEO titles, and descriptions for tags.These backend settings are the foundation for the display labels of the front-end template.

AnQiCMS template engine supports tag syntax similar to Django, through specific tags, we can easily call and render data configured on the backend from the front end. For article tags, the system mainly provides the following key template tags:

  • tagListTagUsed to obtain the list of tags associated with the document, or to obtain the list of tags for the entire site.
  • tagDetailTagUsed to obtain the detailed information of a single tag, such as displaying the description of the tag on the tag detail page.
  • tagDataListTagUsed to retrieve the list of articles under a specific tag, which is the core of building the tag detail page.

Display the tag list of articles on the article detail page and generate links.

On the article detail page, we usually need to display all the tags associated with the current article. These tags should be clickable to guide users to explore more related topics.

First, make sure that your article detail page template (usually{模型table}/detail.html) has been correctly introduced. In the template, you can usetagListtags to get the current article tags.tagListTag without specifyingitemIdWhen a parameter is specified, it will default to reading the document ID of the current page to retrieve the tags associated with the current article.

A typical implementation is to iterate over the obtained tag set and create links for each tag:

{# 假设您正在文章详情页的模板中 #}
<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:

  • {% tagList tags %}Declared a namedtagsvariable that contains all the tag data for the current article.
  • {% for item in tags %}Start looping throughtagsEach tag in the variable. In each loop,itemrepresents an independent tag object.
  • {{ item.Link }}The link address of the tag on the website will be output, which usually points to the article list page under the tag.
  • {{ item.Title }}The name of the tag will be output, which is the clickable text displayed to the user.
  • title="{{ item.Title }}"The attribute added a tooltip text on hover for tag links, enhancing user experience and SEO friendliness.

Display the site's popular tags or tag cloud.

In addition to displaying tags on the article detail page, you may also want to display the site's popular tags or a tag cloud in the website's sidebar, footer, or a dedicated tag index page.

To achieve this, you can use it againtagListtags, but this time you need to go throughlimitparameters to control the number of displays, and go throughitemId="0"Explicitly indicates that it is not associated with any specific article, but to obtain the tags of the entire site.

For example, in the sidebar template (such as)partial/sidebar.html) Display 10 popular tags:

<div class="tag-cloud">
    <h3>热门标签</h3>
    {% tagList tags with itemId="0" limit="10" %} {# 获取全站前10个标签 #}
        {% for item in tags %}
            <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
        {% endfor %}
    {% endtagList %}
</div>

Please note,tagListlabel'slimitThe parameter allows you to control the number of tags returned,itemId="0"Make sure it retrieves tags from the entire site, not just a specific article.

Build the tag detail page

When a user clicks on a tag link, they should be taken to a page that displays all the articles under that tag. AnQiCMS usually names the template for such pages astag/list.htmlortag/index.html.

In these tag detail pages, we will mainly usetagDataListtags to get the list of articles associated with the current tag.tagDataListTags are displayed on the tag detail page, automatically identifying the tag ID of the current page. At the same time, in order to better display the content, we will also combinepaginationtags to implement pagination of the article list.

The followingtag/list.htmlAn example template:

{# tag/list.html 模板内容 #}
{% comment %}
首先,获取当前标签的详细信息,以便在页面标题或描述中使用
{% endcomment %}
<h1>标签:{% tagDetail with name="Title" %}</h1>
<p>{% tagDetail with name="Description" %}</p>

{% comment %}
接着,获取该标签下的文章列表并进行分页展示
{% endcomment %}
<div class="tag-articles">
    {% tagDataList archives with type="page" limit="10" %} {# 获取当前标签下每页10篇文章 #}
        {% for item in archives %}
            <div class="article-item">
                <h2><a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a></h2>
                <p>{{ item.Description }}</p>
                <p>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }} | 浏览量:{{ item.Views }}</p>
                {% if item.Thumb %}
                    <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
                {% endif %}
            </div>
        {% empty %}
            <p>该标签下暂时没有文章。</p>
        {% endfor %}
    {% endtagDataList %}

    {% comment %}
    分页导航
    {% endcomment %}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            <ul>
                {% if pages.FirstPage %}
                    <li {% if pages.FirstPage.IsCurrent %}class="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 item in pages.Pages %}
                    <li {% if item.IsCurrent %}class="active"{% endif %}><a href="{{ item.Link }}">{{ item.Name }}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>
                {% endif %}
                {% if pages.LastPage %}
                    <li {% if pages.LastPage.IsCurrent %}class="active"{% endif %}><a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a></li>
                {% endif %}
            </ul>
        {% endpagination %}
    </div>
</div>

This code first utilizestagDetailDisplay the title and description of the current tag, then proceed throughtagDataListList all related articles in the form oftype="page"), and finally usepaginationthe tag to render the complete page navigation.

By using the above method, you can flexibly display article tags and their links in the AnQiCMS template, greatly enriching the content organization form of the website and enhancing the browsing experience of users on the website.


Frequently Asked Questions (FAQ)

Q: How to control the number of tags displayed on the article detail page?A:tagListTag supportlimitThe parameter is used to control the number of tags displayed. For example, if you only want to display the first 5 tags of the article, you can modify the code to{% tagList tags with limit="5" %}.

Q: Can I only display tags under specific categories?A: Yes,tagListTag supportcategoryIdParameters. You can specify one or more category IDs (separated by commas), for example{% tagList tags with categoryId="1,2" %}This will only display tags related to articles with category ID 1 or 2.

Q: Will a tag still be displayed in the tag cloud if it is not associated with any articles?A:tagListThe tag defaults to returning tags that are associated with articles. If a tag has no articles, it is usually nottagListReturn, therefore it will not be displayed in the tag cloud. If you want to handle this situation, you can{% for item in tags %}add in the loop{% empty %}a tag to display 'No tags' or similar prompts.

Related articles

How to build a list page of articles with filtering conditions, such as filtering by custom properties?

As an experienced CMS website operation personnel of an enterprise, I know how to meet user needs through refined content presentation.Build a list page of articles with filtering conditions, especially on custom attributes, is an important means to enhance user experience and help users quickly find the information they need.AnQi CMS, with its flexible content model and powerful template tags, makes this process efficient and intuitive.Build a list page of articles filtered by custom attributes, mainly involving the following core stages: first, define and configure these custom attributes in the background management system; next,

2025-11-06

How to retrieve and display the custom parameter field value of the article through template tags in AnQiCMS?

In AnQiCMS (AnQiCMS), the custom parameter field provides great flexibility and scalability for website content.As a website operator familiar with AnQi CMS, I am well aware of how to effectively utilize these fields and display them on the website front end to meet diverse content display needs.This article will elaborate on how to use the AnQi CMS template tags to obtain and display the custom parameter field values of the article.### Understanding the customized parameter fields of AnQi CMS AnQi CMS allows users to customize the content model according to business needs

2025-11-06

How to display a list of recommended articles related to the current article content, supporting keyword search or manual association?

As an experienced CMS website operation person in the security industry, I know that high-quality content and accurate recommendations are important for improving user experience and website SEO.In the article detail page, effectively displaying recommended articles related to the current content can not only extend the user's visit time and reduce the bounce rate, but also optimize and improve the page weight and crawling efficiency through internal links.AnQi CMS provides flexible tags, supporting us to build this recommendation list through keywords or manual methods.### Implementing related article recommendations in AnQi CMS AnQi CMS uses a powerful template tag system

2025-11-06

How to get the title, link, and thumbnail of the previous and next articles of the current article?

As an experienced website manager familiar with the operation of Anqi CMS, I fully understand the importance of the details of content presentation to user experience and the overall performance of the website.The front and rear navigation function of the article detail page can not only effectively guide users to continue browsing and reduce the bounce rate, but also is an effective means to enhance the relevance between pages and optimize the internal link structure.An enterprise CMS provides a concise and efficient template tag, allowing us to easily achieve this function.--- ### Enhance Content Coherence: Implement Previous and Next Article Navigation in AnQiCMS In Website Content Operation

2025-11-06

How to get the detailed information of a specific Tag, such as Tag name, description, index letter, and Logo?

As an experienced CMS website operator, I am well aware of the importance of content tags (Tags) in website content management and SEO optimization.They can not only help us organize content more flexibly and improve user experience, but are also one of the key factors for search engines to understand the structure of website content.Today, I will delve deeply into how to obtain and display detailed information of specific tags in the Anqi CMS template, including tag names, descriptions, index letters, and Logos, to achieve a more refined front-end display.###

2025-11-06

How to display all articles under a specified Tag with pagination support?

As an experienced security CMS website operations manager, I know that high-quality and easily understandable content is crucial for user experience.Today, we will discuss how to implement the article list display under specified tags in AnQi CMS, and add practical pagination functions. This is of great importance for improving user browsing experience and website SEO. ### Understanding the Importance of Tag Pages In Anqi CMS, tags (Tags) are a powerful content organization tool.They allow us to associate the content of different categories even different models through common themes or keywords

2025-11-06

How to retrieve and display the comment list of an article in AnQiCMS template, including parent and child comments

As a website operator who is deeply familiar with the operation of Anqing CMS, I know that the comment area is an indispensable part of the website content ecosystem. It is not only an important place for user interaction but also an extension and amplification of content value.A lively and well-organized comment section can significantly enhance user loyalty and promote a positive interaction cycle between content creators and readers.

2025-11-06

How to quickly deploy AnQiCMS Docker container using 1Panel?

As an experienced security CMS website operator, I am well aware of the importance of an efficient and stable content management system for corporate operations.AnQi CMS with its high-performance and enterprise-level features in Go language, provides a solid foundation for our content operations.Using a visual management tool like 1Panel, combined with Docker container technology, can greatly simplify the deployment process, allowing us to focus more quickly on content creation and optimization.Below, I will give a detailed introduction on how to quickly deploy AnQiCMS Docker container through 1Panel

2025-11-06