How to display the AnqiCMS document Tag list on the front page and support filtering by letter or category?

Calendar 👁️ 66

In a content management system, a tag (Tag) is a powerful tool that helps us organize content more flexibly and improve the efficiency of users in finding relevant information.AnQiCMS as an efficient enterprise-level content management system naturally also deeply integrates powerful tag functions.If you are hoping to display a list of document tags on the front end of your website and allow users to filter by letter or category, this article will provide you with a comprehensive guide.

The tagging mechanism of AnQiCMS

AnQiCMS treats tags as independent content entities, which is different from the traditional 'keyword' concept.In the background, you can set a unique name, index letter, even define a custom URL alias and SEO information for each tag, which greatly enhances the independence and SEO-friendliness of the tag.It is also worth mentioning that the tags of AnQiCMS are generic across models, which means the same tag can be associated with documents under different content models (such as articles, products), providing great flexibility for content association.These tags have been fully introduced in AnQiCMS V2.1.0 and continue to be optimized.

Display all tag lists on the front page

To display all the tags on the website, we usually have a dedicated page, such as the website's 'Tag Homepage' to present them. According to AnQiCMS template design conventions, the corresponding template file for this page is typically located in the template directory you are currently using.tag/index.html.

in thistag/index.htmlIn the template file, we can usetagListtags to get all the tag data. To better manage and display a large number of tags, we usually use the pagination feature together:

{# /template/{你的模板目录}/tag/index.html #}

{# 获取所有标签并分页展示,每页显示20个 #}
{% tagList tags with type="page" limit="20" %}
    <div class="tag-list-container">
        {% for item in tags %}
            <a href="{{item.Link}}" class="tag-item">
                {{item.Title}} <span class="tag-count">({{item.ArchiveCount}})</span>
            </a>
        {% empty %}
            <p>目前还没有任何标签。</p>
        {% endfor %}
    </div>

    {# 引入分页组件,显示5个页码按钮 #}
    {% pagination pages with show="5" %}
        <div class="pagination-nav">
            {% if pages.FirstPage %}
                <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>
            {% endif %}
            {% if pages.PrevPage %}
                <a class="page-link" href="{{pages.PrevPage.Link}}">上一页</a>
            {% endif %}
            {% for pageItem in pages.Pages %}
                <a class="page-link {% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
            {% endfor %}
            {% if pages.NextPage %}
                <a class="page-link" href="{{pages.NextPage.Link}}">下一页</a>
            {% endif %}
            {% if pages.LastPage %}
                <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">尾页</a>
            {% endif %}
        </div>
    {% endpagination %}
{% endtagList %}

In the code above, we go throughtagList tags with type="page" limit="20"Gained all tags and specified the pagination mode and number of items per page.item.LinkWill automatically generate the URL for the tag detail page.item.TitleIs the display name of the tag, anditem.ArchiveCountThe number of documents associated with the label can be displayed subsequently.paginationThe label is responsible for rendering the standard pagination navigation.

Supports sorting tags by letter.

To facilitate users' quick location of tags, sorting by alphabet is a very practical feature. We can add a letter navigation bar at the top oftag/index.htmlthe page.

Firstly, we need to generate A-Z letter links. AnQiCMS's template engine supports some filters to assist us in completing this task. We can usemake_listThe filter splits a string into a character array, then traverses to generate links:

{# 继续在 /template/{你的模板目录}/tag/index.html 文件中 #}

<div class="alphabet-filter">
    <a href="/tags" class="letter-item {% if not urlParams.letter %}active{% endif %}">全部</a>
    {% for char in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"|make_list %}
        <a href="/tags?letter={{char}}" class="letter-item {% if urlParams.letter == char %}active{% endif %}">{{char}}</a>
    {% endfor %}
</div>

{# 接着是上面的 tagList 和 pagination 代码 #}
{% tagList tags with type="page" limit="20" letter=urlParams.letter %}
    {# ... 标签列表和分页代码 ... #}
{% endtagList %}

Here, we useurlParams.letterto get the parameter value in the current URL.letterIf it exists, we will pass it tourlParams.letter.tagListlabel'sletterParameters, in this waytagListIt will only return tags that start with the letter.make_listThe filter can convert the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" into an iterable list of characters.

Supports filtering tags by category

We can also filter by the category of the tags in addition to filtering by alphabet.Although the tags of AnQiCMS itself do not belong directly to any category, the documents belong to categories, and the tags are associated with the documents.Therefore, the "Filter by category" here usually refers to filtering out tags related to documents under a certain category.

To implement this feature, we first need to obtain the website category list, which can be done bycategoryListtags. Then, generate a filter link for each category and select thecategoryIdpass totagListTags:

{# 继续在 /template/{你的模板目录}/tag/index.html 文件中 #}

<div class="category-filter">
    <a href="/tags" class="category-item {% if not urlParams.categoryId %}active{% endif %}">所有分类</a>
    {% categoryList categories with moduleId="1" parentId="0" %} {# 假设这里筛选文章模型的顶级分类 #}
        {% for category in categories %}
            <a href="/tags?categoryId={{category.Id}}" class="category-item {% if urlParams.categoryId|integer == category.Id %}active{% endif %}">{{category.Title}}</a>
        {% endfor %}
    {% endcategoryList %}
</div>

{# 接着是上面的 alphabet-filter, tagList 和 pagination 代码 #}
{% tagList tags with type="page" limit="20" letter=urlParams.letter categoryId=urlParams.categoryId|integer %}
    {# ... 标签列表和分页代码 ... #}
{% endtagList %}

In this example, we usecategoryListtags to get the top-level categories under the article model.urlParams.categoryIdto get the category ID parameter in the URL. Please note,urlParams.categoryId|integerThe filter converts URL parameters to integer type to ensurecategory.Idcorrect comparison. When the user clicks on a category link,tagListThe label will be based oncategoryIdParameters to display the tags associated with the documents under the category.

Tag details page: Display the document list under a specific tag.

When a user clicks on a tag, they will usually enter the detail page of the tag, displaying all documents associated with this tag. According to the template design convention of AnQiCMS, the corresponding template file of this page is usuallytag/list.html.

Intag/list.htmlIn the template, we can usetagDetailtags to get the details of the current tag, as well astagDataListtags to get the list of all documents under the tag.

”`twig {# /template/{your template directory}/tag/list.html #}

{# Get the details of the current tag #} {% tagDetail currentTag with name=“Title” %}

<h1>标签: {{currentTag}}</h1>
<p>{% tagDetail with name="Description" %}</p>

{% endtagDetail %}

{# Retrieve the document list under the current tag and display it with pagination #} {% tagDataList archives with type

Related articles

How to implement the AnqiCMS document parameter filtering function on the front page to help users quickly locate content?

How to help users quickly find the information they are interested in on increasingly rich content websites is a crucial operational challenge.Users often need to filter content based on specific conditions rather than browsing aimlessly.AnqiCMS provides a powerful document parameter filtering function that allows you to easily achieve this goal on the front page, greatly enhancing user experience and content discoverability.

2025-11-09

How to display the custom parameter fields of AnqiCMS documents on the front page, such as authors, sources, and so on?

In website operation, the flexibility of the Content Management System (CMS) is crucial.AnQi CMS, with its powerful customizability, allows us to add various custom parameter fields to content (such as articles, products, etc.) to meet diverse display needs.These custom fields, such as the 'author', 'source', 'model', 'color' of products, etc., can greatly enrich the dimensions and practicality of content.How can we elegantly present these personalized custom parameters to visitors on the website frontend after we have added them in the background of the document

2025-11-09

How to display the AnqiCMS related document list on the front page to increase content relevance and user stay time?

In content operation, we all hope that users can stay longer on the website and browse more content.An精心 crafted article is indeed important, but how to connect it with other relevant content to form a content matrix is the key to improving user experience and reducing bounce rate.Imagine, after a user finishes reading an article about 'AnQi CMS Core Features', if the page below automatically recommends 'How to Build an E-commerce Site with AnQi CMS' or 'AnQi CMS Template Creation Tutorial', wouldn't it be more attractive for them to continue exploring?

2025-11-09

How to display the 'Previous' and 'Next' documents of the current document on the front page to enhance the user's browsing experience?

In AnQiCMS (AnQiCMS), adding "Previous" and "Next" navigation links to the front-end document pages is an important means to enhance user browsing experience and extend user stay time.When a user finishes reading an article, these links can guide them naturally to discover more related content, avoid interrupting page browsing, and effectively reduce the bounce rate, which also helps to enhance the overall weight of the website's content. AnQi CMS as a rich-featured Go language content management system, built-in with a powerful template tag system, allowing website operators to flexibly control content display. Among which

2025-11-09

How to display detailed information of a specific AnqiCMS Tag on the front page, such as description and Logo?

AnqiCMS as an efficient content management system not only provides rich content publishing and management functions, but also provides great flexibility for the display of front-end pages.In website operation, properly using tags (Tag) can effectively enhance the organization of content, user experience, and search engine optimization (SEO).When a user browses to a specific tag, if the page can directly display the detailed information of the tag, such as its description and exclusive Logo, it will undoubtedly greatly enhance the professionalism and attractiveness of the page.Next, we will explore how to use the AnqiCMS front page

2025-11-09

How to display the document list associated with a specific Tag of AnqiCMS on the front page?

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website.The AnqiCMS Tag (tag) feature is exactly for this purpose.By cleverly using Tag, we can not only provide users with more accurate content navigation, but also make search engines better understand the structure of the website content. This article will focus on how to clearly and effectively display the document list associated with a specific Tag in AnqiCMS on the front page of a website.###

2025-11-09

How to display the AnqiCMS comment list on the front page and support pagination and parent-child comment display?

AnQi CMS provides a convenient comment function for website content interaction, allowing visitors to express their opinions on articles, products, and other content.For website operators, how to clearly display these comments on the website front-end and provide user-friendly pagination and parent-child comments (i.e., reply function) is a key link to improving user experience.Below, let's discuss how to achieve this goal in AnQi CMS.

2025-11-09

How to build and display AnqiCMS's message form on the front page, supporting custom fields and captcha?

In website operation, establishing effective interaction with visitors is a key step to improve user experience and collect valuable feedback.Anqi CMS knows this point well, therefore it provides us with a powerful and flexible feedback form function, which not only supports basic feedback collection but also allows for easy customization of fields and captcha, making the website's interactive module efficient and secure.Next, we will delve into how to build and display a fully functional comment form on the front page of Anqi CMS, supporting custom fields and captcha, thereby better serving our users.

2025-11-09