How to highlight the currently selected filter option generated by `archiveFilters`?

Calendar 👁️ 62

In modern website operations, user experience (UX) is undoubtedly one of the core competitive advantages.When a user is faced with a vast amount of content and needs to quickly locate the required information through filtering, a clear and intuitive filtering mechanism is crucial.AnQiCMS (AnQiCMS) deeply understands this, providing a powerful content model and flexible template tags, among whicharchiveFiltersLabels are the magic tools for building advanced filtering functions. However, simply providing filtering options is not enough. How can users easily identify what conditions they have selected at a glance?This is what we need to delve into deeply today - inarchiveFiltersHighlight the currently selected filter option in the generated filter conditions.

As an experienced website operations expert, I know that every detail can affect the user's conversion rate and retention.Make the filter conditions 'alive', providing clear visual feedback is a key step to improving user experience.

Understand the filtering function in AnQiCMS.

AnQi CMS relies on its efficient architecture based on the Go language and rich template tags, providing a solid foundation for building complex website functions for content operators. In terms of content display, especially for list pages that require multi-dimensional filtering, archiveFiltersLabels play a core role. They allow us to dynamically generate a series of filtering conditions available for users to choose from, such as product brands, price ranges, or the publication year and author of articles.

These filter conditions are usually presented in a list form, and the content list will be reloaded after each condition is clicked.But if the user is not clear about which conditions have taken effect, they may feel confused and even repeat their selections, thereby affecting browsing efficiency.Therefore, providing visual highlight feedback for the currently selected filter option is crucial for enhancing usability and user satisfaction.

In-depth analysisarchiveFiltersdata structure

To implement the highlighting of filtering conditions, we first need to understandarchiveFiltersthe data structure of label output. When we use{% archiveFilters filters with moduleId="1" allText="全部" %}such a label call, it will return an array object namedfilters.

ThisfiltersEach element in the array represents a filter dimension, such as "color", "size", or "price". Each dimension object typically containsName(Parameter name, such as "color") andFieldName(Corresponding parameter field name, such as "color").

It is more important that, within each filtering dimension, there are also multiple specific options stored initem.Itemsthis sub-array. For example, under the 'Color' dimension,item.ItemsOptions may include "red", "blue",

Each specific filter option (i.e.,item.Itemsofvalobject) has several key properties:

  • LabelThis is the filter text that the user sees on the page, like 'Red'.
  • LinkThis is the URL to which the page will jump after clicking the filter option, which includes the corresponding filter parameters.
  • IsCurrent:This is the key to our highlighting implementation! IsCurrentIt is a boolean value, and its value is only true when the filter option is the selected condition on the current page.true.

Highlighting intelligent filtering conditions

HavingIsCurrentan understanding of properties, highlighting becomes effortless. We just need to traversearchiveFiltersFilter options are generated by a simple conditional judgment, to addIsCurrentWithtruea specific CSS class to an item, such asactive.

Let's look at a specific code example, which is usually placed in your list page template (for examplearticle/list.htmlorproduct/list.html) in:

{# 筛选条件区域 #}
<div class="filter-area">
    <div class="filter-title">参数筛选:</div>
    {% archiveFilters filterGroups with moduleId="1" allText="全部" %}
        {% for group in filterGroups %}
        <div class="filter-group">
            <span class="group-name">{{group.Name}}:</span>
            <ul class="filter-options">
                {% for option in group.Items %}
                <li class="filter-item {% if option.IsCurrent %}active{% endif %}">
                    <a href="{{option.Link}}" class="option-link">{{option.Label}}</a>
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

{# 假设这是您的内容列表部分,此处省略具体代码 #}
<div class="content-list">
    <!-- 这里是使用 archiveList 标签或其他方式展示的内容列表 -->
    <!-- ... -->
</div>

In this code, we first go througharchiveFiltersThe tag obtained the filter condition set and named itfilterGroups. Then, we use nestedforLoop to traverse each筛选dimension (group) and its included filter options (option)

The key is this line of code:<li class="filter-item {% if option.IsCurrent %}active{% endif %}">. It will check the currentoptionofIsCurrentProperty. If it istrueit will automatically be<li>add an element toactiveClass.

Finally, you just need to define in the website's CSS file.activeThe style of the class to distinguish visually from the unchecked items. For example:

/* style.css */

.filter-options {
    list-style: none; /* 移除默认列表样式 */
    padding: 0;
    margin: 0;
    display: flex; /* 让筛选项横向排列 */
    flex-wrap: wrap;
}

.filter-item {
    margin-right: 10px;
    margin-bottom: 5px;
}

.option-link {
    display: block;
    padding: 5px 10px;
    border: 1px solid #eee;
    border-radius: 4px;
    color: #333;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.filter-item.active .option-link {
    background-color: #007bff; /* 选中项的背景色 */
    color: #fff; /* 选中项的文字颜色 */
    border-color: #007bff;
    font-weight: bold; /* 选中项的字体加粗 */
}

.option-link:hover {
    background-color: #f0f0f0;
}

.filter-item.active .option-link:hover {
    background-color: #0056b3; /* 选中项的hover效果 */
    border-color: #0056b3;
}

By following these steps, when the user selects 'Red', after the page is reloaded, the 'Red' filter option will have a prominent blue background and white text, clearly indicating the current filter status.

Optimize user experience and注意事项

Highlight the filter conditions, not just for aesthetic improvements, but for a huge enhancement in user experience.It can effectively reduce the cognitive burden of users, avoid repeated choices, and give them a clear understanding of the current content scope.

In practice, we still need to pay attention to some details. For example,allTextThe "All" option defined by the parameters, usually when no specific filter options are selected,IsCurrentThe property will betrueTherefore, it can also participate well in highlighting.

When designing highlight styles, in addition to color changes, consider adding borders, bold fonts, and other visual elements to ensure that different user groups (including those with visual impairments) can clearly identify the selected state. At the same time, keep the click area of the filter link large enough and provide appropriate:hoverEffect, it can further enhance the interactive experience.

Of Security CMSarchiveFilterswith the tag andIsCurrentThe combination of properties provides a direct and efficient way to build insightful and user-friendly content filtering interfaces, greatly simplifying the workload of template development, allowing us to focus more on content presentation and the formulation of operational strategies.


Frequently Asked Questions (FAQ)

Q1:archiveFiltersCan the tag be used on any page?

A1:archiveFiltersThe tag is mainly designed for content list pages or category pages, such as article lists, product lists, etc. It will be based on the context of the current page (such as model ID, category ID) or throughmoduleIdConditions explicitly specified by parameters are used to generate filtering options. When used on a general page that does not contain content list logic, it may not generate filtering conditions correctly due to a lack of context.

Q2: If I don't want to display the 'All' option of a filter group, what should I do?

A2:archiveFiltersTags provide aallTextParameter, the default value is “All”. If you do not want the “All” option to be displayed for a certain filter group, you can set it toallText=false. For example:{% archiveFilters filterGroups with moduleId="1" allText=false %}. This will not generate a link for the 'All' option in the filter group.

**Q3:IsCurrentDoes the property support high

Related articles

Does the `archiveFilters` tag provide hooks or extension points to allow developers to customize filtering logic?

AnQiCMS (AnQiCMS) is an efficient and customizable enterprise-level content management system that provides many conveniences in content display and management.For developers, understanding the internal mechanisms and extension points is the key to achieving advanced customization.Today, let's delve into the `archiveFilters` tag and see if it provides hooks or extension points for custom filtering logic.### Deeply understand the functional orientation of the `archiveFilters` tag First

2025-11-06

How to display the number of documents under each filter option in the `archiveFilters` tag?

As an experienced website operation expert, I know that every detail can affect the final effect in terms of user experience and website data analysis.When a user is browsing the filter list, if they can clearly see the number of documents included under each filter option, it not only significantly improves their browsing efficiency but also helps them find the content they need faster, thus optimizing the conversion path.AnQiCMS (AnQiCMS) provides a solid foundation for us to meet this requirement with its flexible and powerful functions.Today, let's delve deeper into

2025-11-06

Besides the document homepage and category pages, where else can the `archiveFilters` tag be used in the templates?

As a senior website operation expert, I fully understand that in order to truly bring out the value of CMS functions, one needs to deeply explore their potential and apply them to a wider range of scenarios.The Anqi CMS template tag system is designed to be quite flexible, and the `archiveFilters` tag is one of the tools that can greatly enhance the user's content filtering experience. It is clearly stated in the document that the `archiveFilters` tag is mainly used on the document homepage or document category templates, and is combined with the document pagination list.This is undoubtedly its most common and direct application scenario.

2025-11-06

Does the `archiveFilters` tag support responsive layout and filtering display in mobile templates?

In the Anqi CMS ecosystem, many operators and developers are concerned about a core issue: whether our powerful `archiveFilters` tag can be flexibly responsive in mobile template layouts and display filtering?As an experienced website operations expert, I can clearly tell you that the answer is affirmative, but it contains the unique template design philosophy and implementation mechanism of Anqi CMS, which is worth in-depth exploration.

2025-11-06

`archiveFilters` tag can be displayed with different filtering conditions based on user permissions or user groups?

As an experienced website operation expert, I am well aware that flexibility and personalization are the key to improving user experience and achieving fine-grained operation in content management systems.Especially in scenarios involving user permissions and content display, how to present differentiated content or features according to the needs of different user groups is a common problem for operators to think about.Today, let's delve into whether the `archiveFilters` tag in AnQiCMS can display different filtering conditions based on user permissions or user groups?This topic. ### AnQiCMS

2025-11-06

If the background adjusts the content model parameters, will the `archiveFilters` tag automatically update the displayed filtering conditions?

AnQiCMS (AnQiCMS) is favored by a wide range of content operators for its flexible content model and efficient operational capabilities.Today, we will delve into a commonly concerned issue: will the filtering conditions displayed on the front-end page using the `archiveFilters` tag automatically update after we adjust the content model parameters in the background?As an experienced website operations expert, I can clearly tell you that the answer is yes: **when the Anqi CMS background content model parameters are adjusted**

2025-11-06

Does the `archiveFilters` tag support filtering based on Tag tags, in addition to custom parameters?

AnQi CMS is an efficient enterprise-level content management system that provides many flexible tags and features for content display and management.Among them, the `archiveFilters` tag is often used by website operators to build complex document filtering interfaces due to its powerful filtering capabilities.HoweverToday, let's delve deeply into this issue. ###

2025-11-06

How to keep the `archiveFilters` tag parameters concise and readable when passed in the URL?

As an experienced website operations expert, I am well aware of the importance of URL structure for the SEO performance, user experience, and even brand image of a website.In a flexible and efficient content management system like AnqiCMS, the `archiveFilters` tag provides us with powerful dynamic filtering capabilities, but how to ensure that these filtering parameters in the URL are concise and readable to avoid long and disordered URLs is a problem that every operator needs to consider carefully. Today

2025-11-06