How to use the `archiveFilters` tag to implement multiple condition combination filtering on the front end?

Calendar 👁️ 73

AnQiCMS provides flexible and powerful content management capabilities, one very practical feature being the use ofarchiveFiltersLabels achieve multi-condition combination filtering on the front end. This undoubtedly greatly enhances the user experience and the discoverability of content for websites with rich content and the need for users to search for information based on different dimensions, such as product displays, real estate rentals, recruitment information, and so on.

Let's delve deeper into how to usearchiveFiltersLabel, build an intuitive and efficient filtering system for your website.

The foundation of building a filtering feature: custom content model fields

Once you can usearchiveFiltersBefore filtering tags, first make sure that the custom fields that can be used for filtering are already set in your content model.AnQi CMS allows you to flexibly define content models according to your business needs.

For example, if you are creating a real estate website, you may have the following filtering options:

  • House type: Residential, commercial, apartments, etc. (single selection or dropdown selection)
  • Room typeOne bedroom, two bedrooms, three bedrooms, etc. (single choice or drop-down selection)
  • Decorating situationFinely decorated, raw, simple decoration (single choice or drop-down selection)
  • Area rangeFor example, 50-70 square meters, 70-90 square meters (range of numbers, which needs backend logic to handle, but the frontend display can be preset options)

These filtering conditions are defined in the 'Content Management' -> 'Content Model' section of the AnQi CMS backend.When you edit or create a model, you can add custom fields to the model and select an appropriate field type, such as 'Single choice' or 'Drop-down choice'.These fields' default values will be used as specific options for frontend filtering.AnQi CMS will automatically identify these parameters defined as filterable.

Get to knowarchiveFiltersTag

archiveFiltersThe main function of the tag is to automatically generate the HTML structure of the front-end filtering conditions based on the filtering fields defined in your content model. These links will cleverly carry query parameters for the content list tagarchiveListIdentify and filter data.

Basic usage is as follows:

{% archiveFilters filters with moduleId="1" allText="全部" %}
    {# 在这里循环输出筛选条件 #}
{% endarchiveFilters %}

here we define a variable namedfiltersvariable to receive the data output from the label.

The label accepts several important parameters:

  • moduleId: Specify the content model ID to filter. This is essential as it tells the system which model (such as, the article model ID is 1, the product model ID is 2) to generate the filter condition for.
  • allText: Used to set the display text for default options like 'All' or 'Unlimited'. If you do not want to display the 'All' option, it can be set toallText=false.

filtersA variable will return an array object, eachitemrepresents a filterable field (such as “house type”, “layout” ). Eachitemalso includes aItemsArray, this array contains all the available filter options under the field (such as "Residential", "Commercial").

Each filter option (val) includes the following information:

  • Label: Display text for the filter value, such as 'Residential.'
  • Link: The URL will redirect after clicking the filter value, and this URL will automatically include the filter parameters.
  • IsCurrentA boolean value indicating whether the current filter value has been selected, can be used to addactiveStyle.

Combine the filter conditions with the content list:archiveListandpagination

archiveFiltersThe tag itself only generates the UI and links for the filter options, it needs to work with thearchiveListandpaginationtag together to achieve the complete filtering and pagination functions.

The key isarchiveListThe tag is intype="page"In this mode, it will automatically read the query parameters from the URL and filter the document based on these parameters.archiveFiltersThe generated link takes advantage of this.

Let's look at a complete example, assuming we have a model ID of 1 for a "real estate" model, and we have already defined custom filtering fields such as "house type" and "layout."}

<div class="filter-area">
    <h3>房产筛选</h3>
    {% archiveFilters filters with moduleId="1" allText="不限" %}
        {% for item in filters %}
        <ul class="filter-group">
            <li class="filter-name">{{ item.Name }}: </li>
            {% for val in item.Items %}
            <li class="filter-option {% if val.IsCurrent %}active{% endif %}">
                <a href="{{ val.Link }}">{{ val.Label }}</a>
            </li>
            {% endfor %}
        </ul>
        {% endfor %}
    {% endarchiveFilters %}
</div>

<div class="content-list">
    {% archiveList archives with moduleId="1" type="page" limit="10" %}
        {% for item in archives %}
        <div class="article-card">
            <a href="{{ item.Link }}">
                <h4>{{ item.Title }}</h4>
                <p>{{ item.Description|truncatechars:100 }}</p>
                <div class="meta-info">
                    <span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    <span>阅读量:{{ item.Views }}</span>
                    {# 如果有自定义字段,例如“户型”,可以直接调用 #}
                    <span>户型:{% archiveDetail with name="户型" id=item.Id %}</span>
                </div>
            </a>
            {% if item.Thumb %}
            <a href="{{ item.Link }}" class="thumb">
                <img alt="{{ item.Title }}" src="{{ item.Thumb }}">
            </a>
            {% endif %}
        </div>
        {% empty %}
        <p class="no-content">很抱歉,当前筛选条件下没有找到相关内容。</p>
        {% endfor %}
    {% endarchiveList %}

    <div class="pagination-area">
        {% pagination pages with show="5" %}
            <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{ pages.FirstPage.Link }}">首页</a>
            {% if pages.PrevPage %}
            <a class="page-link" href="{{ pages.PrevPage.Link }}">上一页</a>
            {% endif %}
            {% for item in pages.Pages %}
            <a class="page-link {% if item.IsCurrent %}active{% endif %}" href="{{ item.Link }}">{{ item.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}
            <a class="page-link" href="{{ pages.NextPage.Link }}">下一页</a>
            {% endif %}
            <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{ pages.LastPage.Link }}">尾页</a>
        {% endpagination %}
    </div>
</div>

In this example:

  1. archiveFiltersGenerated filter options such as “House Type”, “Room Layout”, etc., each option'sLinkwill automatically add the corresponding query parameters (such as?房屋类型=住宅&户型=三室)
  2. archiveListUsemoduleId="1"andtype="page"It will check the query parameters in the current URL and filter out the corresponding real estate documents according to these parameters.
  3. paginationThe label ensures that the filtering results can be correctly paginated when there are multiple pages, and the pagination links will also retain the current filtering conditions.

Tips in practice

  • Style beautification is the key.: The user interface (UI) of the filtering function is crucial. You need to add appropriate CSS styles to the class, making the filtering conditions clear and the selected state obvious..filter-group/.filter-optionand.activeAdd suitable CSS styles to the class, making the filtering conditions clear and the selected state obvious.
  • Custom filter parameter namingIn the background, when defining custom fields, it is recommended to use concise and meaningful English names as "Call Field" (FieldName), which will be reflected in the URL query parameters.Although the system supports Chinese, English parameters are more universal.
  • EnsurearchiveListSet correctly: Must be inarchiveListsettype="page", otherwise the filtering and pagination functions will not work properly.
  • Filter parameters and URLWhen the user clicks the filter criteria, you will see something like in the browser address bar.yourdomain.com/module/list.html?户型=三室&房屋类型=住宅Such a URL. Anqi CMS will automatically parse these parameters and filter them.

In this way, you can easily implement a powerful multi-condition combination filtering function in AnQiCMS, greatly enhancing the interactivity and user satisfaction of the website content.

Frequently Asked Questions (FAQ)

1. My custom field is inarchiveFiltersnot displayed, or displayed but not filterable, why is that?

This is usually because your custom field is not properly configured as a filterable type. Please make sure to edit the model you are using in the background "Content Management" -> "Content Model", and add the custom field for the model.

Related articles

How to display website traffic statistics in the background in the form of charts?

In website operation, understanding and analyzing traffic data is a key link in formulating effective strategies and optimizing website performance.AnQiCMS (AnQiCMS) fully understands this, and therefore provides an intuitive and convenient traffic statistics function in the background, allowing operators to easily grasp all the data of the website in the form of charts, thereby better driving content and marketing decisions.The traffic statistics feature of Anqi CMS is designed to provide a comprehensive view of website performance.It not only records the user's visit behavior, but also pays special attention to the activities of search engine spiders, which is crucial for SEO work.Through the background data statistics module

2025-11-07

How to use the `tdk` tag in the template to display the current page's canonical URL?

In website operation, we all hope that our content can be accurately understood and efficiently indexed by search engines.Among them, Canonical URL (standard link) is a very important concept.It can help us solve the problem of duplicate content that may arise due to similar content or accessible from multiple URLs, clearly telling search engines which is the main version of the content, thus concentrating the ranking weight of the page and avoiding dispersion.AnQi CMS as an efficient and flexible content management system, fully considers the needs of SEO optimization, and built-in powerful TDK (Title

2025-11-07

How to display the website's logo image on the front page?

The website logo is the core of the brand image, it not only enhances the professionalism of the website, but also deepens users' recognition of the brand.In AnQiCMS, displaying your logo image on the front page is a straightforward and flexible process, mainly involving backend settings and template code adjustments. ### Step 1: Upload and configure your Logo on the AnQiCMS backend Managing the Logo image of the website is very convenient in AnQiCMS.First, you need to upload the Logo image to the system's backend.

2025-11-07

How to enable and configure the website comment form in AnQiCMS and display custom fields?

In AnQiCMS, creating an interactive guest留言表单 form that collects feedback and can be flexibly configured with custom fields is a very practical feature.AnQiCMS provides a simple and efficient way to achieve this goal, whether it is backend settings or frontend display, it can be easily mastered. ### Enable and configure the message function on the back-end Usually, when you want website visitors to contact you or collect their feedback, a message form is the preferred choice.

2025-11-07

How to use the `tagList` tag to display the associated tag (Tag) cloud of the article?

AnqiCMS provides a series of powerful and flexible tags to help us manage and display website content more efficiently.Among many features, the article tag (Tag) is a very practical feature that can effectively organize content, enhance the internal link structure of the website, and make it convenient for visitors to quickly find related topics of interest.Today, let's delve into how to use the `tagList` tag to elegantly display related tags in the AnqiCMS template, and even build a dynamic 'tag cloud'.

2025-11-07

How to batch modify keywords in the article content in the background and synchronize them to the front display?

In website content operation, the accuracy and timeliness of keywords are crucial.With market changes or SEO strategy adjustments, we often need to make batch modifications to the keywords of a large number of articles on the website.If done manually, it will undoubtedly consume a lot of time and effort.幸运的是,AnQiCMS(AnQiCMS)提供了高效的批量关键词替换功能,让这一process变得得心应手,并能确保修改后的内容无缝同步到前台显示。

2025-11-07

How to display the unique content and images of a custom page (single page)?

In website operation, we often need to create some unique content and personalized page layouts, such as 'About Us', 'Contact Information', or a specific event detail page.AnQiCMS (AnQiCMS) has provided us with a powerful custom page (single page) feature, which not only allows us to easily manage the text content of these pages, but also flexibly display their exclusive images and customized layouts.How to specifically operate, so that the custom page has its own unique content and image display method?

2025-11-07

How to display the AnQiCMS built-in system language package switch feature on the front page?

AnQi CMS provides a flexible mechanism to allow your website to better serve users in different languages around the world.When you want to implement language switching on the front page, the tags and backend configuration built into AnQiCMS can well meet this need.Understanding AnQiCMS language package mechanism First, we need to clarify the concept of "language package" in AnQiCMS.The system language package built into AnQiCMS is mainly responsible for switching the website backend interface and the language of the**system built-in prompts, labels, etc.**on the front-end page.

2025-11-07