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