How to display a list of all used tags (Tags) in the website?

Calendar 👁️ 75

In website operation, tags are an important tool for content organization and user discovery.A clear and complete list of tags can not only help users quickly find the content they are interested in, but also improve the website's SEO performance and guide search engines to better understand the structure of the website content.AnQi CMS provides powerful and flexible tag management and display functions, allowing you to easily display the list of all tags used on the website.

Display method of the site-wide tags list

If you want to set up a special page on the website to display all the tags used, a "tag cloud" or "tag index" page is usually created. In Anqi CMS, this can be done through template tagstagListcooperate with pagination tagspaginationto achieve.

First, you can go to the custom template directory (for example,templatein the foldertag/index.htmlor in the page template you customized), and usetagListLabel to get all tag data. To implement pagination, we willtagListto specifytype="page", and set the number of tags displayed per page (limit)

For example, the following code snippet shows how to retrieve and display all tags and provides pagination functionality:

<div class="tag-list-container">
    {% tagList tags with type="page" limit="50" %} {# 获取所有标签,每页显示50个 #}
        {% if tags %}
            <ul class="tag-cloud">
                {% for item in tags %}
                    <li><a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <p>目前网站还没有任何标签。</p>
        {% endif %}
    {% endtagList %}

    {# 接着,使用分页标签来展示分页导航 #}
    {% pagination pages with show="5" %} {# 显示5个页码按钮 #}
        <nav class="pagination-nav">
            {% if pages.PrevPage %}
                <a href="{{ pages.PrevPage.Link }}" class="prev">上一页</a>
            {% endif %}
            {% for p in pages.Pages %}
                <a class="{% if p.IsCurrent %}active{% endif %}" href="{{ p.Link }}">{{ p.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}
                <a href="{{ pages.NextPage.Link }}" class="next">下一页</a>
            {% endif %}
        </nav>
    {% endpagination %}
</div>

In this code block:

  • {% tagList tags with type="page" limit="50" %}Will retrieve all tags from the database and organize them in a paginated manner.tagsIs the variable name you define for the tag list,type="page"Specified to enable pagination mode,limit="50"It controlled the number of tags displayed per page.
  • {% for item in tags %}Loop through each tag obtained.
  • {{ item.Link }}It will output the URL address of the label,{{ item.Title }}It displays the name of the tag.
  • {% pagination pages with show="5" %}Tags are used to generate pagination navigation.pagesIs the variable name you define for pagination data,show="5"indicating that up to 5 page number buttons are displayed. By judgingpages.PrevPage/pages.NextPageand traversingpages.PagesYou can build a complete "Previous page", "Next page", and numeric page number navigation.

Through such settings, your website can have a rich and easy-to-navigate full-site tag list page.

Show related tags on the individual document page.

In addition to the site-wide tag list, you may also want to display related tags at the bottom or side of each document (article, product, etc.) on the details page. This can also be done bytagListTag implementation, but needs to be配合itemIdthe parameter.

In the template of the document detail page (for examplearchive/detail.html) assuming the current document ID can be obtained througharchive.IdYou can display related tags like this:

<div class="document-tags">
    <h3>本文标签:</h3>
    {% tagList docTags with itemId=archive.Id %} {# 获取与当前文档(archive.Id)相关联的标签 #}
        {% if docTags %}
            <ul>
                {% for tag in docTags %}
                    <li><a href="{{ tag.Link }}" title="查看更多关于{{ tag.Title }}的内容">{{ tag.Title }}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <p>该文档暂无标签。</p>
        {% endif %}
    {% endtagList %}
</div>

here,itemId=archive.IdIt is crucial, it tellstagListTags only return tags associated with the current document ID.docTagsIt is the variable name you define for the tag list of this specific document.

Flexible use to enhance user experience

Whether it is a full-site tag list or document-related tags, the tag function of Anqi CMS provides high flexibility.You can customize the CSS styles for these tags according to the design style of the website, such as displaying them in different font sizes (simulating a tag cloud), different colored backgrounds, or adding spacing between them, etc., to enhance the visual effects and user experience.

Reasonably display and utilize tags, which can not only help users conveniently explore the website content, form a good internal circulation, but also help search engines better capture and understand the thematic relevance of the website, thereby improving the overall SEO effect of the website.


Frequently Asked Questions (FAQ)

How can I make the site tag list display in alphabetical order?

By default,tagListTags are sorted according to the creation or update time of the tags in the background. If you need to sort them in alphabetical order (or by the first letter of the pinyin), the front-end of Anqi CMS is currentlytagListThe tag does not provide a direct sorting parameter. You can consider two methods: one is to follow a certain order when naming and managing tags in the background management interface;The second is to get the tag list through JavaScript on the front end, and then use JavaScript's sorting function to implement custom sorting display.

2. Can you only display tags under specific categories instead of all site tags?

Can.tagListTags provide acategoryIdThe parameter is used to specify which tags associated with documents under a certain or several specific categories should be displayed. For example,{% tagList tags with categoryId="1,2" %}It will display the tags used by documents with category IDs 1 and 2.

How to limit the display quantity of tag lists, for example, to only show the top 10 most popular tags?

tagListlabel'slimitParameters can help you control the display quantity. For example,{% tagList tags with limit="10" %}Only the first 10 tags will be displayed. It should be noted that,tagListIt does not have a built-in "hot" sorting parameter, it usually takes the top N by default sorting (such as creation time).If you need to sort by 'popular' (such as frequent usage), you may need to customize the data retrieval logic on the backend or implement it through more advanced template variable processing.

Related articles

How to retrieve and display detailed content of a specific independent page?

Our Anqi CMS provides great flexibility in content management, especially for pages that need to display independent, static information, such as "About UsThese are called "independent pages" or "single pages", their content is usually relatively fixed, but they also need to be independently displayed and have search engine friendly features.How can we efficiently retrieve and display the detailed content on these specific independent pages in AnQi CMS?

2025-11-09

How to display a list of all independent web pages of the website?

In AnQiCMS, the independent pages of a website play a crucial role, usually carrying core information such as "About Us", "Contact Information", "Privacy Policy", etc. They are an indispensable part of building website trust and perfecting the information architecture.This article will introduce how to effectively manage and display these independent page lists in Anqi CMS. ### Understanding the 'Independent Page' in AnQi CMS In the context of AnQi CMS, what we refer to as the 'Independent Page' corresponds to the 'Single Page' feature in the system.These pages and articles

2025-11-09

How to display subcategories on the category page, or show the article list when there are no subcategories?

In website operation, the content display logic of category pages has an important impact on user experience and information architecture.We often encounter such needs: when there are subcategories under a category, it is preferred to display these subcategories to facilitate users in navigating more finely;And if the category does not have subcategories, then directly display the list of articles under the category, to avoid the page content being empty or the navigation level being too deep.AnQiCMS (AnQiCMS) provides flexible template tags that can easily achieve this dynamic display effect.### Understand the dynamic display logic of the category page To implement the intelligent display of the category page

2025-11-09

How to retrieve and display the list of all categories on the website?

In Anqi CMS, the website category list is the foundation for building clear navigation, enhancing user experience, and optimizing search engine rankings.Whether it is to establish a classification system for articles, products, or other content models, AnQiCMS provides flexible and powerful tools to easily obtain and display these classifications.One of the core concepts of AnQiCMS is to make content management efficient.It organizes the content into different "content models", such as common article models and product models.Each content model can have an independent classification system. Understanding this is the first step to obtaining the classification list.

2025-11-09

How to retrieve and display all articles associated with a specific tag?

AnQi CMS: Accurately locate and display the list of articles under specific tags In AnQi CMS, the Tag is a very practical feature that can help us classify and manage website content more finely, improve the efficiency of users discovering relevant content through keywords, and also greatly benefit the SEO performance of the website.By adding meaningful tags to articles, we can link together similar topics scattered across different categories, providing users with a more cohesive and in-depth reading experience.This article will delve into how to make use of the powerful template tag features of AnQi CMS

2025-11-09

How to dynamically set the page title (Title), keywords (Keywords) and description (Description)?

In website operation, the page title (Title), keywords (Keywords), and description (Description) are the foundation of Search Engine Optimization (SEO).They not only convey the core information of the page content to search engines, but also directly affect the click-through rate of users on the search results page.AnQiCMS (AnQiCMS) fully understands its importance and provides a flexible and powerful mechanism that allows users to dynamically and accurately set these SEO elements based on the content of different pages.This article will discuss in detail how to be efficient in AnQiCMS

2025-11-09

How to display the website name and logo in the template?

The website's name and logo, like a person's name and face, are an indispensable symbol.They are not only the core of the brand image, but also the key to improving the professionalism of the website, enhancing user trust, and making it easy to remember.In AnQiCMS, elegantly present these important identification elements in the website template, simpler and more flexible than you imagine.Understanding the basic settings of AnQiCMS website In AnQiCMS, the basic information of the website such as the name and Logo is concentrated in the background "Global Function Settings".You can log in to the back end and navigate to

2025-11-09

How to display the website filing number and copyright information in the footer?

In website operation, the website footer usually contains important information, such as filing number and copyright statement.This information is not only a manifestation of the website's compliance, but also a window for displaying the website's professionalism.AnQiCMS provides a convenient way to manage and display this information.We will introduce in detail how to display the filing number and copyright information in the footer of the AnQiCMS website.

2025-11-09