How to display all Tag tags associated with a document in AnQi CMS template?

Calendar 👁️ 53

AnQi CMS is an efficient and flexible content management system that provides rich features for content operators, among which 'tags' play a key role as an important means of content classification and association, enhancing the structuralization of website content, optimizing user experience, and SEO.As an experienced website operations expert, I know how to maximize the value of content using these tools.Today, let's talk about how to accurately display all the Tag tags associated with a document in the AnQiCMS template.

The importance of tags and the tag management mechanism of AnQiCMS

Before delving into template operations, let's first review the value of tags (Tag).Tags are not just small labels for content; they are more like keywords for content, helping users quickly find related information, enhancing cross-references within the site's content, which is crucial for user engagement and search engine optimization (SEO).By tags, we can connect content scattered across different categories and even different models, based on common themes or keywords, forming a content network that greatly enriches the depth and breadth of users' browsing.

AnQiCMS is well-versed in this, providing an intuitive and powerful tag management feature.In the background, when you edit or publish a document, you can directly select existing tags in the "Tag label" field, or quickly create a new tag by entering it and pressing the Enter key.The system will automatically associate these tags with the current document.In addition, AnQiCMS also provides an independent 'Document Tag' management page, allowing you to uniformly view, edit, and manage the tags of the entire site, ensuring the standardization and consistency of the tag system.

The core of displaying tags in the template:tagListTag

To display all the tags associated with a document in the AnQiCMS template, we mainly rely on a powerful template tag——tagListThis tag is designed to retrieve and display tag lists, it can intelligently recognize the current page context, and can also specify the tag set to be retrieved through parameters.

AnQiCMS template syntax is similar to the Django template engine, variables are enclosed in double curly braces{{变量}}where logical control uses single curly braces and the percent sign{% 逻辑 %}Understanding this is crucial for writing template code.

Step to display tags on the document detail page

Assuming you are visiting an article or product detail page, you want to display all related tags at the bottom of the page.

  1. Locate the template file:Generally, the template file for the document (article or product) detail page is located in the current theme directory.{模型table}/detail.htmlfor examplearticle/detail.htmlorproduct/detail.html)。If you have specified a custom template for a particular document, you need to edit the corresponding template file.

  2. UsetagListTag get tag list:In the document detail page,tagListTag has a very convenient feature: when you do not specifyitemIdWhen a parameter is specified, it will automatically identify the document ID of the current page and retrieve all tags associated with the document. This greatly simplifies the operation.

    Therefore, you can insert the following code at an appropriate location in the template (such as below the document content, in the sidebar, etc.)

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

    Let's decode this code:

    • {% tagList tags %}This istagListThe start tag. We assign the list of tags obtained to a variable namedtagsbecause we did not specifyitemIdthe parameter, the system will default to finding the tags associated with the current document.
    • {% for item in tags %}: This isforLoop, used for iterationtagsEach label in the variable. Inside the loop, the data of each label is accessed throughitemthe variable.
    • <a href="{{ item.Link }}" class="tag-item">{{ item.Title }}</a>: This is the display format of each label.
      • {{ item.Link }}: The link address of the tag will be output. Clicking it will usually jump to the document list page under the tag.
      • {{ item.Title }}: The name of the tag will be output.
      • class="tag-item"Here we added a CSS class name for you to beautify the tag style later, making it more in line with the overall design of the website.
    • {% endfor %}:forEnd of the loop marker.
    • {% endtagList %}:tagListThe end tag of the tag.
  3. Styled tags (optional but recommended):To make the tags look nice on the page, you can add the corresponding styles in the website's CSS file, for example:

    .document-tags {
        margin-top: 20px;
        padding: 15px;
        background-color: #f8f8f8;
        border-radius: 5px;
    }
    .document-tags strong {
        font-weight: bold;
        margin-right: 10px;
        color: #333;
    }
    .tag-item {
        display: inline-block;
        padding: 5px 10px;
        margin-right: 8px;
        margin-bottom: 8px;
        background-color: #e0e0e0;
        color: #555;
        text-decoration: none;
        border-radius: 3px;
        font-size: 14px;
        transition: background-color 0.3s ease;
    }
    .tag-item:hover {
        background-color: #007bff;
        color: #fff;
    }
    

Advanced Techniques: Control Label Display More Flexibly

AlthoughtagListThe default behavior is already very intelligent, but in some specific scenarios, you may need more fine-grained control:

  • Display Tags for Specific Documents:If you want to use the label for a non-document detail page or need to display a specific document (other than the current document), you can useitemIdParameters. For example, to display all tags of the document with ID 123:

    {% tagList specificTags with itemId="123" %}
        {% for item in specificTags %}
            <a href="{{ item.Link }}">{{ item.Title }}</a>
        {% endfor %}
    {% endtagList %}
    
  • Limit the number of tags displayed:If a document is associated with many tags, you may only want to display a part of them.limitParameters can help you control the number of tags displayed, for example, showing only the first 5 tags:

    {% tagList topTags with limit="5" %}
        {% for item in topTags %}
            <a href="{{ item.Link }}">{{ item.Title }}</a>
        {% endfor %}
    {% endtagList %}
    
  • Handling the case without tags:If a document does not have any associated tags, by defaultforThe loop will not output anything inside. To provide a better user experience, you can make use offorrepeatedlyemptya clause to display a prompt message:

    {% tagList tags %}
        {% for item in tags %}
            <a href="{{ item.Link }}">{{ item.Title }}</a>
        {% empty %}
            <span>暂无相关标签。</span>
        {% endfor %}
    {% endtagList %}
    

By using the above method, you can easily and flexibly display any tags associated with documents in the AnQiCMS template, thereby effectively improving the organization and user experience of the website's content.

Frequently Asked Questions (FAQ)

  1. Q: If the document is not associated with any tags, what will the page display?A: If the document is not associated with any tags,{% tagList tags %}in the labelforThe loop will not output anything. To provide a better user experience, you can{% for %}use labels inside{% empty %}use a clause to display a prompt text, such as “No related tags available.”

  2. Q:tagListCan the order of the tags obtained be fixed? Can I control their sorting?A:tagListLabels do not provide a direct sorting parameter by default.It usually returns based on the order of creation or association of tags.If you have a specific requirement for the display order of tags, you may need to adjust it in the tag management on the backend, or customize the sorting after obtaining the tag data through JavaScript on the frontend.

  3. Q: Where will I be redirected when I click on the tag? How is this link generated?A: When you use it in the template{{ item.Link }}AnQiCMS will automatically generate the URL corresponding to the tag. After clicking, the user is usually navigated to the

Related articles

How to configure a pseudo-static URL on the Tag tag page to optimize search engines?

Unlock the potential of search engine: AnqiCMS Tag page pseudo-static URL optimization configuration details In the ever-changing Internet world, the visibility of a website is the foundation of its success.For operators, how to make their content easier to be discovered by search engines and achieve good rankings has always been a core issue.AnQiCMS (AnQiCMS) as a system designed for content operations, knows this.

2025-11-06

What are the practices or注意事项 for custom Tag URL alias?

## AnQi CMS Custom Tag URL Alias: Strategies and Practices for Improving SEO and User Experience As a senior website operations expert, I know that every detail can affect the overall performance of the website.In the content management system, Tag tags are not only an important tool for organizing content and facilitating user browsing, but their URL structure is also a key factor in website SEO and user experience.

2025-11-06

How to set independent SEO title and description (TDK) for Tag tags?

AnQi CMS is a management system designed specifically for content operation and SEO optimization, fully aware of the importance of every detail for the website's search engine performance.Tag label, it is not only a supplement to content classification on many websites, but also an important path for users to explore their interests and for search engines to understand the depth of website content.Therefore, setting a separate SEO title, description, and keywords (TDK) for Tag tags is a key step in enhancing its search visibility and user experience.

2025-11-06

What does the 'index letter' feature of Tag tags specifically mean?

As an experienced website operations expert, I know that how to efficiently organize and conveniently retrieve information in a vast amount of content is the key to improving user experience and operational efficiency.AnQiCMS (AnQiCMS) is a system tailored for small and medium-sized enterprises and content operation teams, and it is also quite meticulous in detail design.Today, let's talk about one of the seemingly simple functions that can bring significant convenience to your website - the 'index letter' of Tag tags.What is the 'Index Letter' feature of Tag tags?

2025-11-06

How to limit the number of `{% tagList %}` tags displayed on the page?

## Precisely Control: How to Limit the Number of Tags on the Page in Anqi CMS using `{% tagList %}` Tag Tags play a key role in modern website operations, connecting content, enhancing user experience, and optimizing search engine indexing.They can not only help users find relevant content quickly, but also provide strong support for the internal link structure and SEO strategy of the website.However, as with any excellent tool, it is crucial to use and manage tags reasonably.If we allow the page to load too many tags, it may backfire, leading to redundant pages and slow loading

2025-11-06

How to use the `{% tagList %}` tag to filter and display Tags in alphabetical order?

As an experienced website operations expert, I know that the organization and presentation of website content is crucial for user experience and Search Engine Optimization (SEO).AnQiCMS (AnQiCMS) provides powerful tools for content managers with its flexible template engine and rich tag system.Today, let's delve deeply into a common yet somewhat challenging requirement: how to elegantly sort and display the Tag of the website using the `{% tagList %}` tag.

2025-11-06

If you want to get the details of a Tag label (such as name, link, description), which template tag should you use?

As an experienced website operations expert, I know that flexibly using template tags in such an efficient content management system as AnQiCMS is the key to improving the efficiency of website content display and management.Especially for content organization forms like Tag tags, which are very important, it is crucial to accurately obtain and display their detailed information, which is essential for SEO optimization and user experience.

2025-11-06

The `{% tagDetail %}` tag can get which field data of Tag?

As an experienced website operations expert, I deeply understand the strong potential of Anqi CMS in content management and SEO optimization.Today, we will delve into a very practical template tag in AnQiCMS——`{% tagDetail %}`, which can help us manage and display website tag data more finely, thereby improving user experience and search engine friendliness.

2025-11-06