How to get all Tag lists or Tags of a specified document in AnQiCMS template?

Calendar 👁️ 66

As a senior CMS website operation personnel in the security industry, I am well aware of the importance of content tags (Tags) in website content organization, SEO optimization, and user experience.They can not only help readers quickly find the content they are interested in, but also enhance the internal links of the website and improve the search engine crawling efficiency.In the Anqi CMS template system,tagListThe label is the core tool for us to achieve this goal.

This article will discuss in detail how to flexibly use the Anqi CMS template.tagListTags, to obtain the list of all tags on the website, or accurately obtain the tags associated with a specified document, to help you build a more intelligent and user-friendly website content display.

Understand the content tags in AnQi CMS

In AnQi CMS, content tags (Tags) are a flexible way to classify content, different from traditional categories (Category). Tags are usually more granular, and a document can be associated with multiple tags, and a tag can also be associated with multiple documents.This makes the relationship between the content more rich and interconnected.

The AnqiCMS backend provides comprehensive tag management functions, you can add, edit, and delete operations under the "Content Management" module's "Document Tags".Each tag can be set with a name, index letter, custom URL, SEO title, keywords, and description. This information can be called from the front-end template to build a beautiful and informative tag page.The main role of tags is to provide an entry for quick browsing of related content, enhance the navigation experience within the website, and is also an important part of keyword layout in SEO strategies.

tagListThe core function of template tags

In the template language of AnQi CMS,tagListis a powerful tag, specifically used to retrieve content tags data from websites.It allows us to query and display these tags in various ways, whether it is to list all tags or only display tags related to specific content.

tagListThe basic syntax structure of the tag is:{% tagList 变量名 with 参数 %}, and ends with:{% endtagList %}End. IntagListandendtagListThe content between the tags will be processed for each loop.变量名This is the name specified for the tag list we have obtained, for exampletagsIt will be an array object, and we need to iterate through it to output each tagforin a loop.

List all content tags on the website

To get all available content tags on the website, we can usetagListlabel'sitemIdparameters. Usually,itemIdThe parameter defaults to trying to read the document ID of the current page to obtain related tags. However, if we want to obtain all the tags of the entire website, not just the tags of a specific document, we need to explicitly specifyitemIdis set to"0".

In addition, to ensure that we can obtain enough labels, we can adjustlimitParameter.limitThe parameter specifies the maximum number of tags that can be called, which is usually 10 by default. If your website has many tags, it is recommended to setlimitto a larger value, such as"100"to cover most cases or uselimit="1,100"ofoffsetpattern to get a wider range.

Here is an example of how to get all tags of a website and display their names and links.

<div>
    <h3>所有网站标签:</h3>
    {% tagList allSiteTags with itemId="0" limit="100" %}
        {% if allSiteTags %}
            <ul class="tag-cloud">
                {% for item in allSiteTags %}
                    <li><a href="{{item.Link}}">{{item.Title}}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <p>目前还没有任何标签。</p>
        {% endif %}
    {% endtagList %}
</div>

In this example,itemId="0"indicationstagListDo not try to associate any specific document, but obtain tags from a global perspective.limit="100"Ensure that no more than 100 tags are retrieved. We have also added{% if allSiteTags %}Judge, to elegantly handle cases with no tag data.

Get the tag list of the specified document

When we are on a document detail page, or need to display related tags for a specific document,tagListlabel'sitemIdThe parameter plays a role again.

If you want to get the tags associated with the current document (i.e., the document the user is browsing), you usually do not need to set them explicitly.itemIdbecause the parameter,tagListThe tag is not specified.itemIdWhen, it will default to read the document ID of the current page. However, for the clarity of the code and to avoid potential confusion, it is a good practice to explicitly pass the ID of the current document.The document ID can be accessed byarchiveDetailLabel retrieval.

Assuming we are on a document details page, and we can accessarchive.Idthe ID of the current document:

{# 假设archive.Id是当前文档的ID #}
<div>
    <h3>当前文档的标签:</h3>
    {% tagList currentDocTags with itemId=archive.Id limit="10" %}
        {% if currentDocTags %}
            <div class="document-tags">
                {% for item in currentDocTags %}
                    <span class="tag-item"><a href="{{item.Link}}">{{item.Title}}</a></span>
                {% endfor %}
            </div>
        {% else %}
            <p>该文档未关联任何标签。</p>
        {% endif %}
    {% endtagList %}
</div>

If you need to retrieveNot the current documentjust by selecting the tag list,itemIdSet the parameter to the specific ID of the document. For example, to get all tags of the document with ID 5:

<div>
    <h3>ID为5的文档标签:</h3>
    {% tagList specificDocTags with itemId="5" limit="10" %}
        {% if specificDocTags %}
            <div class="document-tags">
                {% for item in specificDocTags %}
                    <span class="tag-item"><a href="{{item.Link}}">{{item.Title}}</a></span>
                {% endfor %}
            </div>
        {% else %}
            <p>ID为5的文档未关联任何标签。</p>
        {% endif %}
    {% endtagList %}
</div>

In this way, you can control it preciselytagListThe tag range obtained, whether for the entire website or for a specific content.

Filter and display tags of a specific category.

tagListThe tag also supports passing throughcategoryIdParameters to further filter tags. This means you can only display tags associated with documents under specific categories. If you need to display tags for a specific category, you can do so bycategoryId="分类ID"Specify, multiple category IDs can be separated by English commas,separated.

For example, to display tags associated with documents related to category ID 1 and 2:

<div>
    <h3>分类ID 1和2的标签:</h3>
    {% tagList categorySpecificTags with itemId="0" categoryId="1,2" limit="50" %}
        {% if categorySpecificTags %}
            <ul class="filtered-tags">
                {% for item in categorySpecificTags %}
                    <li><a href="{{item.Link}}">{{item.Title}}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <p>这些分类下没有找到相关标签。</p>
        {% endif %}
    {% endtagList %}
</div>

Here we still useitemId="0"Represents not限定specific document, but from all符合categoryIddocuments that meet the conditions to aggregate tags.

The tag fields available in the loop body.

In{% for item in tags %}the loop,itemThe variable represents the current label object. It provides multiple properties for us to call and display to build rich label displays:

  • item.Id: The unique ID of the tag.
  • item.Title: The display name of the label, which is the most commonly used property.
  • item.Link: The tag corresponds to the page link, clicking it will jump to the document list under the tag.
  • item.Description: The tag description information, which can be used for SEO or mouse hover tips.
  • item.FirstLetter: The index letter of the tag name (A-Z).
  • item.CategoryId: If the tag is associated with a specific category, the category ID will be displayed here.

You can flexibly combine these fields within the loop according to the design requirements to display label information.

Display the label list combined with pagination

For creating an independent label archive page (for exampletag/index.html), we may need to display a large number of tags with pagination.tagListThe tag is intag/index.htmlIn the template, you can settype="page"to support pagination functionality. Similar toarchiveList, the navigation after pagination can be displayed throughpaginationtags.

{# 假设在 tag/index.html 模板中 #}
<div>
    <h2>网站标签云</h2>
    {% tagList tags with type="page" limit="50" %} {# 每页显示50个标签 #}
        {% if tags %}
            <ul class="tag-cloud-paginated">
                {% for item in tags %}
                    <li><a href="{{item.Link}}">{{item.Title}}</a></li>
                {% endfor %}
            </ul>
        {% else %}
            <p>抱歉,目前没有可显示的标签。</p>
        {% endif %}
    {% endtagList %}

    {# 标签列表的分页导航 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
            {% if pages.PrevPage %}
            <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
            {% endif %}
            {% for item in pages.Pages %}
            <a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
            {% endfor %}
            {% if pages.NextPage %}
            <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
            {% endif %}
            <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        {% endpagination %}
    </div>
</div>

In this example,type="page"TelltagListprepare pagination data,paginationthe tag is responsible for rendering standard page navigation.

template integration**practice

  • define variable names: fortagListLabeling variables with clear names (such asallSiteTags,currentDocTags) to improve code readability.
  • Handle empty dataAlways use{% if 变量名 %}or{% empty %}clause to handle the case where the tag list is empty, to avoid blank or error display on the page.
  • Performance consideration: Although Anqi CMS has a high efficiency in label query, in some special cases, if you need to display hundreds or even thousands of labels on a page, please pay attention to the page loading performance and consider whether it is really necessary to display so many labels. For the common "label cloud" function, a reasonablelimitThe value is usually between 50-100.
  • Multi-site compatibilityIf you have enabled the multisite feature of AnQi CMS and need to call tags between different sites, make sure to use them correctly.siteIdSpecify the target site with parameters

By the above detailed description and examples, you should already be familiar with the Anq CMS templatetagListThe usage of tags has been fully understood. Mastering these skills will make you more proficient in the operation of Anqi CMS websites, creating more attractive and functional content displays.


Frequently Asked Questions (FAQ)

1. Why do I usetagListAfter the label, only a few labels were displayed instead of all the labels I expected?

This is usually due tolimitLimitation on the default value of the parameter.tagListThe tag is not specified.limitWhen a parameter is specified, the default is usually to display only 10 tags. If you want to get more tags, even all tags, be sure to setlimitthe parameter to a sufficiently large number, such aslimit="100"Or adjust according to the actual number of tags you have. At the same time, if the goal is to obtainalltags, make sure they are also setitemId="0"to avoid being limited to the tags of the current document.

2.tagListCan the tag retrieve those empty tags that are not associated with any documents?

According to the design of Anqi CMS, tags are usually associated with document content.tagListThe tag is mainly used to retrieve those tags that have been referenced by documents or created in the background and are available. If a tag has no association with any document and its background management status is not activated, it may not betagListThe tag is retrieved. The meaning of the tag is usually to aggregate content, so in most cases, an 'empty tag' may not be the target of front-end display.

3. Can I sort the tags by their usage frequency?tagListSort the tags returned?

tagListThe label parameters currently do not provide a direct option to sort by usage frequency (for example, by number of associated documents). It mainly supports sorting throughlimit/letterandcategoryIdFilter. If you need to sort by tag frequency, this may require custom development of the backend logic in AnQi CMS, or fetching all tags via JavaScript on the front end and sorting according to the associated tags.

Related articles

How to implement document parameter filtering in AnQiCMS templates, for example, filtering by house type?

As an experienced CMS website operator for a security company, I know how important it is for users to efficiently find the content they need when visiting a website with a large amount of information.The content filtering function can not only greatly improve user experience, but also is a key factor in optimizing website structure and SEO performance.Today, I will elaborate on how to implement document parameter filtering in AnQiCMS templates, taking 'filtering by house type' as an example, to help your website better serve users.

2025-11-06

How to use the `archiveList` tag to call the document list with specified categories and recommended attributes?

AnQi CMS is an efficient enterprise-level content management system, whose powerful content tags are the core of dynamic and personalized content display.For website operators, mastering these tags, especially `archiveList`, can greatly enhance the flexibility and efficiency of content management.This article will elaborate on how to use the `archiveList` tag to accurately call the document list with specified categories and recommended attributes, helping you to better build website pages that meet user needs and optimize content display.###

2025-11-06

How to use the `archiveDetail` tag in AnQiCMS template to get document details and custom fields?

As an experienced CMS website operation personnel, I am well aware of the core position of content in website operations.We must not only create high-quality content, but also ensure that this content can be presented to users in a **way.In this, the flexible use of templates is crucial. Today, we will delve into a powerful and commonly used tag in AnQiCMS templates, `archiveDetail`, which helps us easily obtain detailed information about documents, including those carefully designed custom fields.###

2025-11-06

How to correctly display Markdown content, mathematical formulas, and flowcharts in AnQiCMS templates?

As an experienced AnQiCMS website operator, I know that it is crucial to display a diverse range of information efficiently and accurately in the increasingly rich online content ecosystem.Markdown is a lightweight markup language that is widely popular for its simplicity and efficiency.And mathematical formulas and flowcharts are essential expressions for conveying science, technology, or complex logic.This article will detail how to properly configure the AnQiCMS template to perfectly present these advanced contents.

2025-11-06

How to use the `system` tag to obtain website name, LOGO, filing number and other system information?

As an experienced CMS website operation personnel, I fully understand the importance of dynamically obtaining basic website information in daily template development and content presentation.To ensure the consistency, ease of maintenance, and efficient management of the website, Anqi CMS provides an extremely convenient `system` tag.This tag allows template developers to directly call various system-level data from the global settings in the background, thereby avoiding the inconvenience brought by hard coding.The website's name, logo, filing number, and other information are key elements in building a brand image and legal compliance.Pass through the `system` tag

2025-11-06

How to set the page title, keywords, description, and attach the website name using the `tdk` tag in AnQiCMS?

As a senior security CMS website operator, I am well aware of the core position of content in website construction and SEO optimization.TDK (Title, Description, Keywords) tags are an important basis for search engines to understand page content and judge the relevance of the page, as well as the information that users see first on the search results page.Efficiently setting and optimizing TDK is crucial for attracting target users and improving website rankings.Our Anqi CMS provides us with flexible and powerful TDK management functions, allowing us to finely control the metadata of each page

2025-11-06

How to use the `stampToDate` tag to format timestamps in AnQiCMS templates?

As an experienced website operator deeply familiar with Anqi CMS, I know the importance of content timeliness and presentation for user experience.In website content management, the timestamp (Timestamp) is a common way to record the time of content publication and update, but displaying the timestamp directly is not intuitive for users.Therefore, formatting timestamps into readable date and time formats is a key factor in enhancing the professionalism and user-friendliness of a website.AnQiCMS provides a very convenient template tag `stampToDate`, making this operation effortless

2025-11-06

How to get the contact information configured in the `contact` tag of AnQiCMS template?

As an experienced website operator for Anqi CMS, I am well aware of the core position of content in website construction and user interaction.Effectively and conveniently displaying contact information is an indispensable part of a website's functionality, directly affecting the efficiency and willingness of users to communicate with the company.In AnQiCMS, we provide a simple and powerful template tag——`contact`, allowing you to easily display the contact information configured in the background on the website front-end.--- ###

2025-11-06