How to filter and display the Tag list based on index letters in AnQiCMS template?

Calendar 👁️ 64

Hello, users of AnQiCMS! As an experienced website operation expert, I know that in today's increasingly rich content, how to efficiently manage and display content is the key to improving user experience and optimizing SEO.Today, let's talk about a very practical feature in AnQiCMS: how to filter and display the Tag list in templates based on index letters, making your website content navigation smarter and more convenient.

Master AnQiCMS Tag Management: Filter tags by index alphabetically to make content navigation smarter and more efficient

As the content of the website grows continuously, Tag (tag) as a flexible content organization method can effectively link related content together, helping users discover more information of interest.However, when the number of your tags reaches a certain scale, how to clearly display these tags on the front end to avoid users getting lost in a sea of tags has become a question worth pondering.AnQiCMS provides an elegant solution-by using index letters to filter tags, making your Tag list clear at a glance.

Why do we need to filter Tag by index alphabetically?

Imagine a website with hundreds or even thousands of tags. If all tags were simply piled together, it would be very difficult for users to find tags of a specific topic. Sorting by index letters is like creating a 'alphabetical index dictionary' for your tag library, which brings many obvious advantages:

  • Improve user experience:Users can quickly locate tags based on the first letter of their memory, greatly saving search time and making the browsing experience smoother.
  • Optimize website navigation:Structure the tag list to form a clear letter navigation, which is not only aesthetic but also conforms to the habits of users reading traditional dictionaries, reducing the cost of learning.
  • Improve SEO performance:A clear structure and friendly navigation path helps search engines better crawl and understand website content, thereby potentially improving the ranking of relevant keywords.
  • Manage large-scale tags:For websites with a large amount of content, this filtering method is an effective strategy for managing and displaying tags, to avoid the page being too long.

Basic Tag in AnQiCMS: Understanding Index Letters

In the AnQiCMS backend, when creating or editing document tags, you will find a field named "Index Letter".This is a very critical setting that allows you to specify an uppercase English letter (A-Z) for each tag.This letter is the basis for the filtering logic we discussed today.For example, you can set the index letter of the "AnQiCMS" tag to "A", and "Go language" to "G".Ensure that your tags are configured with the correct index letters, which is the basis for sorting by letter.

How to implement tag filtering by index letter in the template?

AnQiCMS's template engine syntax is similar to Django, very flexible. To implement filtering tags by index letter, we need to skillfully combinetagListLabel and some logical judgment.

Firstly, we usually have a dedicated page (such as)/tag/index.htmlor/tag/list.html) To display all the tags. This page needs to be built in two parts: one part is to display the A-Z navigation, and the other part is to display the corresponding tag list based on the currently selected letter.

Step one: Build the letter navigation guide

We can generate a list of letters from A to Z at the top of the page. Here we can use a loop, combined with the current URL in theletterParameters to determine which letter is selected, and to add an "active" state to it (such as highlighting).

<div class="tag-index-letters">
    <a href="/tags" class="{% if not urlParams.letter %}active{% endif %}">全部</a>
    {% set alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"|make_list %}
    {% for char in alphabet %}
        <a href="/tags?letter={{ char }}" class="{% if urlParams.letter == char %}active{% endif %}">{{ char }}</a>
    {% endfor %}
</div>

In this code, we first created a "All" button to display all the tags. Then, we usemake_listThe filter converts the string “ABCDEFGHIJKLMNOPQRSTUVWXYZ” into a character array and traverses it to generate the letter link A-Z.urlParams.letterIt will retrieve the value of the current URL inletterIf the parameter value matches the current traversed letter, we will add a link to that letteractiveClass.

Second step: Display the corresponding Tag list based on the index letter

Under the letter navigation, we need to display the corresponding tags based on the letter selected by the user.tagListTags provide this.letterParameter.

<div class="tag-list-display">
    {% set current_letter = urlParams.letter %}
    
    {% if current_letter %}
        <h2>标签({{ current_letter }})</h2>
        {% tagList tags with letter=current_letter type="page" limit="20" %}
    {% else %}
        <h2>所有标签</h2>
        {% tagList tags with type="page" limit="20" %}
    {% endif %}

    <ul>
        {% for item in tags %}
            <li>
                <a href="{{ item.Link }}">{{ item.Title }}</a>
                <span>({{ item.FirstLetter }})</span>
            </li>
        {% empty %}
            <li>当前字母下没有找到任何标签。</li>
        {% endfor %}
    </ul>

    {# 标签列表分页显示 #}
    {% if tags %}
    <div class="pagination-wrapper">
        {% 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 page_item in pages.Pages %}
            <a class="{% if page_item.IsCurrent %}active{% endif %}" href="{{ page_item.Link }}">{{ page_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>
    {% endif %}
</div>

In this part of the code, we first usesetThe tag places the URL inletterAssigns the parameter value tocurrent_lettera variable for future use. Next, we check for itsifthe statement to judgecurrent_letterexistence:

  • Ifcurrent_letterIf it exists, we use it{% tagList tags with letter=current_letter type="page" limit="20" %}Filter and display the tags under the letter.
  • Ifcurrent_letterIf it does not exist (i.e., the user clicked "All" or visited for the first time), then display all tags.

Related articles

How to limit the number and sorting method of displayed Tags using the `tagList` tag?

## Mastering Website Tags: The Quantity Limit and Sorting Tips of tagList in AnQi CMS In a content management system, tags (Tag) are an important element for connecting content, enhancing user experience, and optimizing search engine crawling.AnQi CMS is an efficient enterprise-level content management system that provides powerful tag management functions and allows developers and operators to flexibly display these tags on the front end through its template tag system.Among them, the `tagList` tag is the core tool for displaying the document related tag list.

2025-11-07

How to call and display the list of all website tags (Tag) in AnQiCMS template?

As an experienced website operations expert, I am happy to give you a detailed explanation of how to efficiently and elegantly call and display the tag (Tag) list of all websites in Anqi CMS templates.AnQi CMS with its powerful content management capabilities and flexible template mechanisms, makes this operation intuitive and practical. --- ## Unveiling AnQi CMS: How to call and display all website tag lists in templates In the era of content marketing and SEO optimization, website tags (Tags) play a crucial role.They can not only help users quickly find relevant content

2025-11-07

What core information can be viewed in the Tag management interface of AnQiCMS?

The AnQiCMS Tag management interface, as your powerful assistant for content operation, is far more than just a simple keyword list.It is a meticulously designed hub that provides you with a series of core information, which is crucial for optimizing your website content structure, improving search engine visibility, and enhancing the user browsing experience.As an experienced website operations expert, I will take you deep into the AnQiCMS tag management interface to view and manage all core information, helping you to master content marketing strategies more efficiently.

2025-11-07

Where will the 'Description Content' field of the AnQiCMS document tag be displayed?

In the daily operation of Anqi CMS, we often use document tags (Tag) to classify and index content, which not only helps users quickly find the content they are interested in, but is also an indispensable part of search engine optimization (SEO).After we have carefully filled in the 'Description' field for each tag, a natural question arises: where will this valuable description information be displayed on the website?Today, let us dive into the secrets of the AnQiCMS document tag "description content" with this senior operation expert.

2025-11-07

Can the `tagList` tag only display Tags associated with specific document IDs?

In the actual operation of AnQi CMS, how to manage content efficiently and accurately is the key to enhancing website value.Tags (Tag) are an important tool for content organization, allowing users to quickly find relevant information and greatly optimize the search engine's ability to crawl and understand website content.Many operators have a question when using the `tagList` tag of AnQi CMS: Can it only display tags associated with a specific document ID, rather than displaying all tags or tags on the current page?Today, let's delve deeply into this issue.

2025-11-07

How to call the Tag data of a specified site in AnQiCMS multi-site mode?

As an experienced website operations expert, I know that how to efficiently and accurately call data while managing multiple content platforms is the key to improving operational efficiency.AnQiCMS, with its excellent multi-site management features, has solved many such challenges for us.Today, let's delve into how the `tagList` tag in the multi-site mode of AnQiCMS can flexibly call the Tag data of a specified site to ensure the accuracy of content operation.### SecureCMS Multi-Site Capabilities Overview First

2025-11-07

How to add pagination to the AnQiCMS Tag list to enhance user experience?

## Optimize AnQiCMS Tag List: How to cleverly add pagination and improve user browsing experience?As an experienced website operations expert, I am well aware of the core value of a content management system, which lies in its ability to provide efficient, customizable, and user-friendly solutions.AnQiCMS, this is an enterprise-level CMS built based on Go language, with its high performance, modular design, and rich SEO tools, it is committed to becoming a powerful assistant for small and medium-sized enterprises and content operation teams.In daily content operation, we often encounter the continuous growth of website content, especially when the number of Tag tags is numerous

2025-11-07

Where does the `tagList` tag return the 'Tag Link' field point to?

As an experienced website operations expert, I fully understand that every detail in a content management system can affect the performance of the website, user experience, and even search engine rankings.Today”。 --- ### AnQiCMS `tagList` tag link field points to where

2025-11-07