How to implement multi-condition filtering display on the article list page with the `archiveFilters` tag of AnQiCMS?

Calendar 👁️ 69

It is crucial to provide users with convenient and accurate content search experience in website operation.As the content of the website becomes richer, simple categorization or keyword search is often not enough to meet the personalized needs of users.This is when the multi-condition filtering function on the article list page becomes particularly important.For AnQiCMS users, it is clever to make use ofarchiveFiltersTags can easily achieve this goal, instantly giving your article list page powerful filtering capabilities.

The core feature revelation:archiveFiltersworking principle

archiveFiltersThe tag plays the role of an intelligent guide in AnQiCMS, its main task is not to filter content directly, butBased on the definition of your website content model, dynamically generate a series of clickable filter linksWhen the user clicks on these links, the page URL will carry the corresponding filter parameters, andarchiveListLabel (when set to pagination mode)type="page"then it will automatically recognize and extract articles that meet these criteria from the database, thereby realizing multi-condition filtering display.

In simple terms,archiveFiltersThe tag's uniqueness lies in the fact that it does not require you to manually write complex filtering logic, you only need to define the custom fields of the content model in the background, and it can automatically read the filtering options of these fields, and generate links with specific URL parameters for each option.This design greatly simplifies front-end development work, allowing you to focus more on user experience and content presentation.

Behind the scenes preparation: Custom fields of the content model

To makearchiveFiltersThe tag plays a role, first you need to make the "behind-the-scenes" preparation in the AnQiCMS backend---that is, define the custom fields that can be used for filtering in your content model.

Imagine if your website is a real estate information platform, you may want users to be able to filter listings based on conditions such as 'property type' (such as residential, apartment, villa), 'area range' (such as 50-80 square meters, 80-120 square meters), and so on.

In the AnQiCMS backend, you can go to 'Content Management' under 'Content Model', select or create a model (such as 'Real Estate Model'), and then add custom fields. The types of these fields are very critical:

  • Single choice: Suitable for situations where options are fixed and the user can only select one, such as 'House Type'.
  • Multiple selections: If the user can select multiple tags or properties at the same time, for example, "Property Features" (with a garden, school district house, etc.).
  • Drop-down selection: Similar to single selection, but presented as a dropdown menu in the UI.

After you have set up the preset options for these custom fields,archiveFiltersTags can intelligently recognize these options and present them as filtering conditions to the user.

Step-by-step operation: How to use in the template.archiveFilters

UnderstoodarchiveFiltersThe principle and background preparation after, let's take a look at how to apply it in the front-end template.

Suppose we have a "real estate model" where we definehouse_type(house type) andarea_range(Area range) Two custom fields.

1. IntroductionarchiveFiltersTag

First, in your article list page template (for example)article/list.htmlorarchive/list.htmlUse it inarchiveFilterstags to get the filtering conditions:

{# 引入 archiveFilters 标签,变量名为 filters,指定模型ID为1,所有选项的文本为“不限” #}
{% archiveFilters filters with moduleId="1" allText="不限" %}
    {# 遍历每个筛选组,例如“房屋类型”、“面积范围” #}
    {% for item in filters %}
    <div class="filter-group">
        <span class="filter-name">{{item.Name}}: </span> {# 输出筛选组的名称,如“房屋类型” #}
        <ul class="filter-options">
            {# 遍历当前筛选组下的所有选项,例如“住宅”、“公寓” #}
            {% for val in item.Items %}
            <li class="filter-item {% if val.IsCurrent %}active{% endif %}">
                <a href="{{val.Link}}">{{val.Label}}</a> {# 输出选项的文本和链接 #}
            </li>
            {% endfor %}
        </ul>
    </div>
    {% endfor %}
{% endarchiveFilters %}

In this code block:

  • archiveFilters filters with moduleId="1" allText="不限": We tell the system to get all the filter conditions for model ID 1 (usually the article or default content model) and set the display text of the 'All' option to 'Unlimited'.filtersIt is a variable defined to receive filtered data.
  • {% for item in filters %}: The outer loop iterates over each filter group, such as "House Type", "Area Range", etc.
    • {{item.Name}}: Display the friendly name of the filter group (such as “House Type”).
    • {{item.FieldName}}: This is the database field name corresponding to the filter group (such ashouse_type), although it is not displayed directly, it is generatedval.LinkPlaying a core role.
  • {% for val in item.Items %}: The inner loop traverses the specific options under each filter group, such as 'Residential', 'Apartment.'
    • {{val.Label}}: Displays the text of the filter options (such as 'Residential').
    • {{val.Link}}This is the most critical part, it will automatically generate one

Related articles

How to dynamically generate page Title, Keywords and Description using `tdk` tag in AnQiCMS template?

In today's internet environment where content is exploding, Search Engine Optimization (SEO) is crucial for a website's visibility.And the Title (title), Keywords (keywords), and Description (description) on the website page, which we commonly call TDK, are key factors for search engines to understand page content, decide whether to display it to users, and whether users will click.In AnQiCMS, a content management system designed specifically for small and medium-sized enterprises and content operation teams, dynamically generating these TDK information is to enhance the website

2025-11-09

How to display the introduction and Banner image of the current category in the AnQiCMS template?

How to make your category page on the website more attractive while clearly conveying information is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) with its flexible template system allows you to easily display the introduction of the current category and personalized Banner images on the category page. We will explore together how to implement this feature in the AnQiCMS template, making your website category page more vivid and professional.### 1. Deeply understand the AnQiCMS template system AnQiCMS

2025-11-09

How to display hreflang tags for users of different languages on the AnQiCMS website?

In the operation of multilingual websites, it is crucial to ensure that search engines can accurately understand the language and region targeted by your content, which is essential for improving user experience and search engine optimization (SEO).The `hreflang` tag is the key tool to solve this problem.It tells search engines that your site has content variants for different languages or regions, thus avoiding duplicate content issues and helping search engines to display the most relevant pages to users of different languages.

2025-11-09

How to format the timestamp into the display format of 'Year-Month-Day Hour:Minute' in AnQiCMS template?

In website content management, the clear display of time information is crucial for user experience.Whether it is the release date of an article or the submission time of comments, a format that conforms to reading habits can make information communication more effective.AnQiCMS provides flexible template functionality, allowing us to easily format timestamps.

2025-11-09

How to automatically convert plain text URLs of articles in the AnQiCMS template to clickable hyperlinks?

In daily website content operations, we often need to mention some external links or URLs in articles, product descriptions, or single-page content.If these URLs appear only in plain text, visitors will not be able to click and jump directly, which will undoubtedly affect the user experience, and may even cause some important information to be ignored.AnQiCMS as a powerful content management system, provides a simple and efficient way to solve this problem, making your content more vivid and interactive.AnQiCMS uses a template engine syntax similar to Django

2025-11-09

How to prevent content scraping on the front end in AnQiCMS, such as displaying watermarks or interference codes?

Protect Originality: AnQiCMS intelligent strategy for front-end content collection prevention In the era of explosive Internet content, the value of original content is becoming more and more prominent, but it also faces the risk of malicious collection.The hard work we put into writing and carefully designed images can be stolen in an instant by others, not only infringing on the creators' labor成果, but also potentially affecting the website's SEO performance and brand image.How can we effectively protect our digital assets?AnQiCMS (AnQiCMS) provides a very practical built-in solution to this issue

2025-11-09

How to use the `if` tag in AnQiCMS templates for conditional judgment to control content display?

When managing content in AnQi CMS, we often need to display different information based on different situations.For example, a blog post may have a thumbnail, while another does not; or a module may only display under certain conditions.At this time, flexibly using the conditional judgment in the template, that is, the `if` tag, can help us achieve these dynamicized content display needs.The AnQi CMS template engine supports syntax similar to Django, where the `if` tag is the core tool for conditional judgments.

2025-11-09

How to build and display the breadcrumb navigation of the current page using the `breadcrumb` tag in AnQiCMS?

In website operation, breadcrumb navigation (Breadcrumb Navigation) is an important element to enhance user experience and website structure clarity.It not only helps visitors quickly understand the position of the current page in the website hierarchy, but also effectively assists search engines in understanding the relationship between website content, and has a positive effect on SEO optimization.For AnQiCMS users, building and displaying breadcrumb navigation is a very convenient operation, thanks to the powerful template tags built into AnQiCMS.### Understand AnQiCMS's

2025-11-09