How to call the Tag list of the specified document in AnQiCMS template?

Calendar 👁️ 69

In AnQiCMS, tagging content (Tag) is an effective way to improve content organization and user experience.These tags not only help search engines better understand the page theme, but also guide users to discover more related content.tagListLabel, makes this operation very simple.

This article will introduce how to use it in AnQiCMS template.tagListTag to call the Tag list of the specified document and provide some practical code examples to help you get started quickly.

Understand the Tag function in AnQiCMS.

In the AnQiCMS content management backend, you can add one or more tags to articles, products, and various types of documents.These tags are managed uniformly in the 'Document Tag' module of the function management, and can be shared for different content models.By tags, we can link related content scattered across different categories, forming a richer content network.

Core tags:tagList

tagListTags are a tool specifically used in the AnQiCMS template engine to obtain the document tag list.It allows you to filter and display tags based on multiple conditions, the most critical of which is the ability to 'specify documents'.

tagListBasic usage of tags

The simplesttagListThe tag call usually assigns the data it retrieves to a variable (for exampletags), and then displays it through a loop:

{% tagList tags with limit="10" %}
    {% for item in tags %}
        <a href="{{item.Link}}">{{item.Title}}</a>
    {% endfor %}
{% endtagList %}

In the above example,tagsThe variable will contain an array of tag objects, you can access them viaitem.LinkGet the link of the tag, throughitem.TitleGet the title of the tag.

Call the key of the specified document Tag:itemIdParameter

To callSpecify the documentThe Tag list,tagListThe core parameter of the tag isitemId.

  1. Get the current Tag list of the document in the document details pageWhen you are on the document details page (for examplearchive/detail.html)tagListwhen you tag the document, ifDefaultitemIdParameter,tagListWill intelligently read the ID of the currently browsing document by default, and return all the Tags associated with the document:

    <div class="article-tags">
        <strong>标签:</strong>
        {% tagList tags with limit="10" %}
            {% for item in tags %}
                <a href="{{item.Link}}" class="tag-item">{{item.Title}}</a>
            {% endfor %}
        {% endtagList %}
    </div>
    

    This method is very suitable for displaying related tags of the current article at the bottom or sidebar.

  2. Call the Tag list of the specified ID document on any page.If you want to call the Tag list of a specific document on a non-document detail page (such as the homepage, category list page, or any custom page), or call it on a document detail pageNot the current documentThe Tag list, you need to use explicitlyitemIdThe parameter and pass the ID of the target document.

    Assuming you know the ID of a document is15You can call its Tag list like this:

    <div class="featured-article-tags">
        <h3>推荐文章的标签:</h3>
        {% tagList featuredTags with itemId="15" limit="5" %}
            {% for item in featuredTags %}
                <a href="{{item.Link}}" class="tag-pill">{{item.Title}}</a>
            {% endfor %}
        {% endtagList %}
    </div>
    

    In this example,itemId="15"Make it cleartagListUse the tag to get the tags associated with the document with ID 15, whilelimit="5"it limits to only display 5 of them.

  3. Get all Tags (not limited to documents)Although it is slightly different from the topic of “The Tag List of the Specified Document”, it is worth mentioning that if you want to get all the Tags on the site (for example, to build a Tag cloud or a Tag index page), you canitemIdis set to"0":

    <div class="global-tag-cloud">
        <h2>所有热门标签:</h2>
        {% tagList allSiteTags with itemId="0" limit="20" %}
            {% for item in allSiteTags %}
                <a href="{{item.Link}}" class="tag-cloud-item">{{item.Title}}</a>
            {% endfor %}
        {% endtagList %}
    </div>
    

    Please note that whenitemIdis set to"0"then,tagListNo longer focusing on a specific document, but rather fetching tags from the global Tag library. At this point,limitThe parameter can be used to control the number of tags displayed in the Tag cloud.

tagListother practical parameters

exceptitemIdother than,tagListIt supports some other parameters to further optimize the display of your Tag list:

  • limit: Controls the number of returned Tags. For examplelimit="10"It will display up to 10 Tags. You can also uselimit="2,10"Start getting 10 Tags from the 3rd Tag.
  • letter: Filter according to the index letter (pinyin initial) of the Tag, for exampleletter="A"Only Tags starting with A will be returned.
  • categoryId: Filter by the category ID of the Tag. If you have set categories for the Tag in the background, you can use this parameter, multiple IDs separated by commas, such ascategoryId="1,2,3".
  • siteId: If your AnQiCMS has enabled multi-site management and needs to call Tag data from other sites, you can specify the site ID through this parameter.

forLoop available Tag field

In{% for item in tags %}the loop,itemThe variable provides rich Tag information, you can call it freely according to your needs:

  • item.Id: The unique ID of the Tag.
  • item.Title: The display name of the Tag.
  • item.Link: Tag's detail page link.
  • item.Description: Tag's description information.
  • item.FirstLetter: Tag's index letter (e.g., 'A', 'B').
  • item.CategoryId: Tag category ID (if any).

Tag settings in content management.

To ensuretagListThe tag can work normally, first you need to add Tag for your document in the AnQiCMS background.

  1. When adding/editing documentsIn the 'Content Management' module, select the 'Publish Document' or 'Edit Document' interface, enter or select an existing tag in the 'Tag Tag' input box.Enter a new tag and press Enter to create and associate.
  2. Manage TagOn the "Content Management" -> "Document Tags" page, you can manage all tags uniformly, including adding, editing, deleting tags and their descriptions, custom URLs, and more.

By following these steps, you can easily manage content tags in the background and flexibly call and display them in front-end templates.

Summary

tagListTags are a powerful and flexible component in the AnQiCMS template, making it easy to display associated document tags. Whether it is to display the tags of the current document or to call the tags of a specific document at any location,itemIdParameters are your powerful assistants.Combine other filtering parameters and loop structures, you can create a highly customized and user-friendly tag display area, thereby enhancing the website's content discovery capabilities and overall user experience.


Frequently Asked Questions (FAQ)

Q1: Why did I use in the templatetagListTag, but no Tag is displayed?

A1:This issue may have several reasons:

  • The document is not associated with TagPlease check the AnQiCMS backend to ensure that the document you want to display the Tag has indeed added the tag.
  • itemIdIncorrect parameter settingIf you call it on a non-document detail page or want to specify a specific document butitemIdthe parameters are not set correctly or an incorrect document ID is entered, the Tag list cannot be retrieved.
  • limitParameter setting too small

Related articles

How to add and manage multiple Tag tags in AnQiCMS?

In a content management system, effectively organizing and presenting information is the key to improving user experience and search engine performance.AnQiCMS provides a flexible Tag feature, which allows for more refined categorization of content, making it easier for users to quickly find content of interest and also provides strong support for website SEO optimization.This article will provide a detailed introduction on how to add and manage multiple Tag tags in AnQiCMS, and discuss its practical value in content operation.

2025-11-08

How can keyword library management in AnQiCMS's SEO tool help optimize website content?

In the increasingly fierce online competition, optimizing website content is the key to attracting and retaining users.For operators who want to stand out in search engines and continuously obtain high-quality traffic, a set of efficient SEO tools is undoubtedly a powerful assistant.AnQiCMS as an enterprise-level content management system provides many practical functions in SEO, among which keyword library management is the core tool for us to optimize website content and improve search engine performance. Imagine your website as a library, and keywords are like indexes guiding readers to the books you provide.

2025-11-08

What special characters are the `escape` and `escapejs` filters used to escape in the AnQiCMS template?

In AnQiCMS template development, to ensure the correct display of content and website security, we often use some built-in filters to handle special characters.Among them, the `escape` and `escapejs` filters are two very important tools, each serving different scenarios, and the types of special characters that need to be escaped are also different.

2025-11-08

How to safely output HTML code in the AnQiCMS template to prevent escaping?

In website operation, we often encounter situations where we need to output content containing HTML code.For example, images, links in the main text, or custom style layouts, etc.When you output this content in an AnQiCMS template, you may find that it is not displayed as interactive elements as expected, but rather displayed in the original HTML code form, for example, `<p>This is a paragraph</p>` becomes `&lt;p&gt;This is a paragraph&lt;/p&gt;`.

2025-11-08

How to use the `tagDetail` tag to get the detailed information of a Tag, such as description and link?

In AnQi CMS, tags (Tag) are an important tool for organizing content, improving SEO, and enhancing user experience.Sometimes, we need not only to list tags, but also to display detailed information about a specific tag on the page, such as its description, link, and even Logo.At this moment, the `tagDetail` tag comes into play, helping us easily obtain this data.

2025-11-08

How to get the associated document list based on Tag ID and how to paginate it for `tagDataList` tags?

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website.AnQiCMS (AnQiCMS) provides powerful tag features, where the `tagDataList` tag is the key tool to help us achieve this goal.It can flexibly retrieve all related document lists based on the specified tag ID, and easily achieve content pagination display by coordinating with other tags.

2025-11-08

What is the difference between the `{{variable}}` and `{% tag %}` syntax in AnQiCMS templates?

When using Anqicms to build a website, templates are the key to dynamic content display.We often see two special syntax structures in template files: `{{variable}}` and `{% tag %}`.Although they are all related to the display and processing of data, they play different roles and have different usage methods.Understanding the difference between them is the first step in efficiently using the Anqi CMS template.

2025-11-08

How to define and use custom variables in AnQiCMS templates, such as the `{% with %}` tag?

In the template design of AnQi CMS, we often encounter scenarios where we need to temporarily store or pass data.In order to make the template code clearer, easier to read, and more powerful, AnQi CMS provides the mechanism for defining and using custom variables, the most commonly used of which are the `{% with %}` tag and the `{% set %}` tag.They can help us handle data flexibly in templates, avoiding repeated calculations or passing complex objects.

2025-11-08