How does the AnQiCMS `tagList` tag display all associated tags of the document?

Calendar 👁️ 68

Easily display the document associated tags: AnQiCMS'stagListIn-depth tag analysis

In content management, tags (Tag) play a crucial role.They can not only help us better organize content and improve the internal link structure of the website, but also play a huge role in search engine optimization (SEO), making it easier for users and search engines to find relevant information.AnQiCMS has fully considered this point and provided a flexible and powerful tag management system. Among them,tagListThe tags are the core tools for displaying document associated tags on our frontend.

Core function analysis:tagListLabel Overview

tagListThe primary purpose of the tag is to retrieve and display all tags associated with the document. Whether it is to display related topics at the bottom of the article or to create a hot tag cloud in the sidebar,tagListAll of them can provide the data we need. This tag allows us to flexibly control the source and quantity of tags according to different needs.

How to associate tags with documents

While usingtagListBefore the label, we need to understand how the label is associated with the document.In the AnQiCMS backend, when we add or edit a document, we will see a 'Tag label' input box.In here, we can add multiple tags to the current document.We can choose an existing label, or create a new one by entering text and pressing Enter.AnQiCMS's tag system is very flexible, the same tag can be shared by documents of different content models (such as articles, products, etc.), which means that tags are cross-category and cross-model.

tagListBasic usage of tags

tagListThe use of tags conforms to the unified syntax of the AnQiCMS template engine. Its basic structure is{% tagList 变量名 with ... %}and{% endtagList %}.

For example, to display all the tags of the current document on the front end, we can define a variable like thistagsto carry these tag data, and then throughforloop traversal output:

<div>
    文档标签:
    {% tagList tags %}
        {% for item in tags %}
            <a href="{{item.Link}}">{{item.Title}}</a>
        {% endfor %}
    {% endtagList %}
</div>

In this example,tagsis an array object,forin the loopitemThe variable represents each independent label object. Each label object containsId(Label ID),Title(label name),Link(Label link),Description(Label description) andFirstLetterInformation of label index letters. We can access and display these data as needed.item.属性名The way to access and display these data.

Deep understandingtagListparameters

tagListThe tag provides multiple parameters, allowing us to control the acquisition of tags more precisely:

  • itemId: Specify the document IDBy default,tagListIt will automatically retrieve the tags associated with the current page document. But if we want to display the tags of a specific document, we canitemId="文档ID"specify. For example,itemId="10"Will retrieve the tags of the document with ID 10. If you want to displayall tagsinstead of tags associated with a specific document, you canitemIdis set to0, that isitemId="0"This is very useful when making a website's tag cloud or hot tags list.

  • limitControl the number of displayed items.We can uselimit="数量"To limit the number of tags displayed. For example,limit="10"It will only display up to 10 tags. If we need to start retrieving a certain number of tags from a certain position (for example, starting from the 2nd tag and getting 5), we can uselimit="offset,数量"Pattern, for examplelimit="2,5".

  • letter: Filter by index letterThis parameter allows us to only display tags with specific initials, for exampleletter="A"It will only display tags starting with A.

  • categoryId: Filter by category IDIf we want to display tags under a specific or a few specific categories (these tags may also be associated with documents in other categories, but here we are only concerned with the tags in the specific category context), we can usecategoryId="分类ID". Multiple category IDs can be separated by English comma,for examplecategoryId="1,2,3".

  • siteId: Multi-site data callFor users who have used the AnQiCMS multi-site management function, if they need to call data from other sites, they cansiteId="站点ID"Specify. Usually, this parameter can be omitted becausetagListIt will default to getting the data of the current site

Practical code examples

Understood the parameters, let's take a look at some specific application scenarios.

1. Display all tags associated with the current document

<div class="article-tags">
    <strong>相关标签:</strong>
    {% tagList currentDocTags %}
        {% for tag in currentDocTags %}
            <a href="{{ tag.Link }}" title="{{ tag.Title }}">{{ tag.Title }}</a>
        {% empty %}
            <span>暂无相关标签</span>
        {% endfor %}
    {% endtagList %}
</div>

2. Display all popular tags (such as in the sidebar)

Here we willitemIdis set to0and limit the number of displayed items.

<div class="sidebar-tags">
    <h4>热门标签</h4>
    <ul>
        {% tagList hotTags with itemId="0" limit="15" %}
            {% for tag in hotTags %}
                <li><a href="{{ tag.Link }}">{{ tag.Title }}</a></li>
            {% empty %}
                <li>暂无热门标签</li>
            {% endfor %}
        {% endtagList %}
    </ul>
</div>

3. Pagination is performed on the dedicated tag list page

AnQiCMS'tagListTags also support pagination, which is usually used for/tag/index.htmlThis label index page. We need totypethe parameter to"page"and combiningpaginationlabel usage

`twig

<h1>所有标签</h1>
{% tagList allPageTags with type="page" limit="20" %}
    <ul class="tag-grid">
    {% for tag in allPageTags %}
        <li>
            <a href="{{ tag.Link }}" title="{{ tag.Title }}">
                <h3>{{ tag.Title }}</h3>
                {% if tag.Description %}
                    <p>{{ tag.Description | truncatechars: 100 }}</p>
                {% endif %}
            </a>
        </li>
    {% empty %}
        <li>暂无标签可显示。</li>
    {% endfor %}
    </ul>

    {# 分页代码 #}
    <div class="pagination-nav">
        {% pagination pages with show="5" %}
            <ul>
                <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
                {% if pages.PrevPage %}
                    <li class="page-item"><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
                {% endif %}
                {% for p_item in pages.Pages %}
                    <li class="page-item {% if p_item.IsCurrent %}active{% endif %}"><a href="{{p_item.Link}}">{{p_item.Name}}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li class="page-item"><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
                {% endif %}
                <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
            </ul>
        {% endpagination %}
    </div>

Related articles

How does the `pageDetail` tag display the detailed content of a single page, such as the 'About Us' page?

In Anqi CMS, single pages (such as "About UsTo present the detailed content of these single pages on the website frontend, we will use a very core and practical template tag——`pageDetail`.This tag helps us accurately extract and display various information on a specified single page, ensuring the flexibility and accuracy of content presentation.

2025-11-07

How does the `pageList` tag display all the titles and links of the individual pages of the website?

In Anqi CMS, using the `pageList` tag to display the titles and links of all single pages is a very common and practical need in website layout and navigation settings.Whether it is used for website footer navigation, sidebar link list, or building a simple HTML site map, the `pageList` tag can help us efficiently achieve these functions. ### Understanding AnQi CMS Single Page Firstly, let's briefly review the "single page" in AnQi CMS.In the Anqi CMS backend management, there is a special "Page Resources" module

2025-11-07

How to retrieve and display detailed information such as description, Logo, etc. for a specific category using the `categoryDetail` tag?

In AnQiCMS template development, obtaining and displaying detailed category information is a key step in building rich and user-friendly pages.The `categoryDetail` tag was created for this purpose, it can help you easily retrieve the description, Logo, custom fields, and other detailed content of a specific category at any location on the page.### `categoryDetail` tag's core function The main function of the `categoryDetail` tag is to obtain detailed data of a single category

2025-11-07

How does the AnQiCMS `categoryList` tag display hierarchical category structures and show category information?

In AnQi CMS, website categories are the foundation for organizing content. Whether it's articles, products, or other custom models, a clear category structure can greatly enhance user experience and the website's SEO effectiveness.The Anqi CMS provides a powerful `categoryList` tag, allowing us to flexibly display single or multi-level classification structures and easily obtain detailed information about each classification.### Master the basic usage of the `categoryList` tag To display the category list, we first need to use the `categoryList` tag

2025-11-07

How does the `tagDetail` tag display the name, description, and other properties of a single tag?

In website content management, tags (Tag) play a multiple role in connecting content, optimizing user experience, and improving search engine visibility.A well-managed tag system not only helps visitors quickly locate the information they are interested in, but also conveys the structured information of the website content to search engines, thereby effectively improving SEO.AnQiCMS (AnQiCMS) fully understands the importance of tags and therefore provides a powerful and easy-to-use `tagDetail` tag, allowing you to flexibly obtain and display detailed information about individual tags.

2025-11-07

How to get and display the associated document list based on a specific tag of `tagDataList`?

In AnQi CMS, tags are not just an auxiliary tool for content management, but also a powerful tool for connecting different thematic content, enhancing the internal link structure of the website, and optimizing the user experience.When you want to display a list of all documents related to a specific tag on a specific page of the website, such as a special page, a tag cloud page, or the sidebar of a specific article, the `tagDataList` tag is your best choice.

2025-11-07

How to flexibly construct and display the top, side, or bottom navigation menu of a website using the `navList` tag?

When building a fully functional website, a clear and intuitive navigation menu is undoubtedly one of the core elements of user experience.AnQiCMS provides a powerful and flexible `navList` tag, allowing users to easily create and manage the top, side, or bottom navigation menus of the website, meeting different layout and content display needs. ### `navList` Tag Basic Usage The `navList` tag is a key tool in the AnQiCMS template engine used to obtain the website navigation list.

2025-11-07

How to generate and display a clear hierarchical breadcrumb navigation on the AnQiCMS page using the `breadcrumb` tag?

In website operations, a clear navigation path is crucial for improving user experience and search engine optimization (SEO).When we browse websites, a concise and clear path can help us quickly locate and understand our current position.

2025-11-07