How to use the `archiveFilters` tag in AnQiCMS template to achieve complex content filtering display?

Calendar 👁️ 71

In AnQiCMS, we often need to display website content in various ways, such as by category, by tag, or even by filtering based on specific content attributes. When faced with more complex content organization needs, such as on a product list page, we not only need to display products but also need to filter them based on custom attributes such as 'color', 'size', 'material', and so on.archiveFiltersThe label can fully showcase its capabilities, helping us easily achieve these complex content filtering and display.

Core features and application scenarios

archiveFiltersThe core role of the tag is to generate dynamic filtering conditions for our content model.It is not just a simple classification filter, but it can go deep into the content model to define custom fields, presenting these field values as filter options to the user.

Imagine that you are building a product display website, where products have standard attributes such as name, description, as well as additional attributes like 'color (red, blue, green)', 'material (wooden, metal, plastic)', and 'size (large, medium, small)'.When users visit the product list page, they hope to quickly find the products they want based on these properties.At this point, if you manually write the logic for each filter condition, it will be a tedious and difficult task to maintain.

archiveFiltersIt is precisely to solve such pain points that it was born. It can read the custom fields you configure for the content model in the AnQiCMS background and automatically generate corresponding filter links, after the user clicks on these links, the content displayed on the page (usually througharchiveListLabel call) it will be updated accordingly to achieve dynamic filtering.

Preparation: Define content model and custom fields.

To utilizearchiveFiltersLabel, first you need to do some preparations on the AnQiCMS background, that is, define the content model and add custom fields.

  1. Enter the backendLog in to the AnQiCMS backend, navigate to 'Content Management' -> 'Content Model'.
  2. Select or create a content model: You can choose from existing 'Article Model', 'Product Model', or create a new content model according to business needs (for example, 'Real Estate Information').
  3. Add custom field:Enter the editing page of the content model you have selected or created. Here, you can add new custom fields, such as:
    • field name:For example, "type of house", "house area", "orientation".
    • Field invocation: Use English letters, such ashouse_type/area/orientation.
    • Field type: In order toarchiveFiltersCan correctly identify and generate filtering conditions, it is recommended to choose 'Single Selection', 'Multiple Selection' or 'Drop-down Selection' and other types.Such, the options you fill in the "default value" (one per line) will be directly used as the optional values of the filter.
    • Mandatory?: Set according to actual needs.
  4. Publish content and fill in the fieldsMake sure you have filled in the data in the corresponding custom fields. Only fields with data,archiveFilterscan generate meaningful filter options.

After completing these steps, our website content will have the foundation for multi-dimensional filtering.

archiveFiltersParameter interpretation of tags

archiveFiltersWhen tags are used, they can be controlled by some parameters:

  • 变量名This is optional. If you specifyarchiveFiltersa variable name (for examplefilters), then the filter data returned will be stored in this variable, and you can access the data through this variable name within the tag. If not specified, it defaults to direct output.
  • moduleIdSpecify the content model ID you want to generate the filter for. For example,moduleId="1"usually represents "article model",moduleId="2"May represent a "product model". This is an important parameter, it tells the label which model to get custom fields from to generate filtering conditions.
  • allText: Set the display text when all filter conditions are not selected, such as "All", "Unlimited". If you do not want to display this option, it can be set toallText=false.
  • siteIdIf you have enabled multi-site management and need to call data from a specific site, you can specify the site ID through this parameter.In most cases, this parameter does not need to be filled in, and the system will automatically retrieve the data of the current site.

UnderstandingarchiveFiltersdata structure

When you usearchiveFiltersLabel and store the result in a variable (for examplefilters), this variable is actually a nested array object, with a clear structure and easy for us to loop render:

  • filtersA list containing multiple filtering dimensions(item).
  • EachitemAn object represents a specific filtering condition group, such as "type" or "area". It includes the following fields:
    • Name: The display name of the filter condition group (for example, "Type of house").
    • FieldName: The custom field name corresponding to the filter condition (for example,house_type)
    • Items: A list containing all the selectable values under the filter condition (val).
  • EachvalAn object represents a specific filtering option, such as "one bedroom one living room" or "Dongcheng District". It includes the following fields:
    • Label: The display name of the filtering option (e.g., "two bedrooms").
    • LinkClick this option to jump to the URL. AnQiCMS will automatically handle the URL parameters and ensure proper filtering.
    • IsCurrentA boolean value indicating whether the current option is selected. This is very useful for adding highlight styles to selected options.

Implementing a filtering interface in the template.

With the above data structure, we can build a dynamic filtering interface in the template. Usually, we would use nestedforloops to traverse the data.

`twig {# Parameter filtering code area #}

<h3>内容筛选</h3>
{% archiveFilters filters with moduleId="1" allText="不限" %} {# 假设模型ID为1,显示“不限” #}
    {% 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-option {% if val.IsCurrent %}active{% endif %}">
                <a href="{{ val.Link }}">{{ val.Label }}</a>
            </li>
            {% endfor %}
        </ul>
    </div>
    {% endfor %}
{% endarchiveFilters %}

{# Document list code area, it will automatically respond to the above filtering conditions #}

{% archiveList archives with moduleId="1" type="page" limit="10" %} {# 同样指定模型ID为1,并开启分页 #}
    {% for archive_item in archives %} {# 遍历筛选后的文档列表 #}
    <div class="content-

Related articles

How to optimize the display link of category and tag pages by using custom URL aliases in AnQiCMS?

In website operation, the URL (Uniform Resource Locator) is not only the address of the content but also an important component of user experience and search engine optimization.A clear, concise URL that contains keywords, which can help users understand the page content faster and also improve the page ranking in search engines.AnQiCMS as an efficient content management system, provides powerful custom URL aliasing functionality, allowing users to flexibly optimize the display links of category and tag pages.### Understand the importance of URL optimization Before delving into the specific operations of AnQiCMS

2025-11-07

How to configure banner images and thumbnails for a single page in AnQiCMS to enrich its visual display?

Today, with the increasing richness of website content, relying solely on text to convey information is no longer enough.Visual elements, such as eye-catching banner images and expressive thumbnails, can attract visitors' attention at first glance and enhance the professionalism and user experience of the website.For AnQiCMS users, cleverly configuring these visual elements for single pages (such as "About Us", "Contact Us", or "Service Introduction", etc.) is a simple operation that can bring great benefits.AnQiCMS fully understands the importance of content display and provides an intuitive backend management interface and a flexible template calling mechanism

2025-11-07

How to configure the category template and document template in the background of AnQiCMS to achieve personalized content display?

As website operators, we all hope that our website content can be presented to visitors in the most attractive way possible.This is not just about visual beauty, but also about how the content structure can better serve users and how to highlight the unique brand character of the website.AnQiCMS fully understands this need, therefore it provides a powerful and flexible template configuration feature in the background, allowing you to achieve highly personalized displays based on different content types - whether it is articles, products, or category pages.Below, let's learn together how to configure category templates and document templates in the AnQiCMS backend

2025-11-07

How to set the automatic compression and thumbnail processing method in AnQiCMS, which affects the image display on the front end?

The quality of website content is often not just reflected in text, but images as visual elements also play a crucial role.In website operation, how to efficiently handle images, ensuring that the images are clear and beautiful while also considering the loading speed, this is the core value of AnQiCMS image processing function.Today, let's delve deeper into how AnQiCMS helps us manage the automatic compression and thumbnail processing of large images, as well as how these settings will affect the display effect of images on the website's frontend.### Say goodbye to slow image loading

2025-11-07

How to replace specific characters in a string in AnQiCMS, affecting the presentation of front-end content?

In website operation, we often encounter situations where we need to modify or adjust the content, which is not just about updating text.Sometimes, we need to replace a specific word on a website with a new expression, or update links in bulk, or even dynamically process certain characters during content presentation.AnQiCMS as an efficient content management system provides a variety of flexible mechanisms to handle string replacement, thereby finely controlling the presentation of front-end content.### Backend bulk replacement: The efficiency tool for global content updates Imagine that the website you operate uses a specific product name

2025-11-07

How to use filters (such as `truncatechars`) in AnQiCMS templates to truncate long text content and display it friendly?

In website operation, how to efficiently display content while ensuring the page is neat and beautiful is a challenge that every operator needs to face.Especially when the title, introduction, or comments of an article are too long, if they are not processed, it is easy to break the page layout and affect the user experience.Luckyly, AnQiCMS provides a powerful and flexible template filter function, among which the `truncatechars` filter and other truncation filters can help us solve this problem elegantly.Optimize Content Display: Why Do We Need to Truncate Text?

2025-11-07

How does AnQiCMS ensure that the front-end displayed content is UTF-8 encoded and avoids garbled characters?

In website operation, content encoding is a crucial link, which directly affects whether users can read the text on the page normally.If encoding is not unified, the appearance of乱码 not only will seriously affect the user experience, but may also lead to information transmission errors.For AnQiCMS, ensuring that the content displayed on the front end is UTF-8 encoded to avoid garbled text issues is a core consideration in its system design and content management.First, Anqi CMS has provided a solid foundation for UTF-8 encoding in its underlying technical architecture.

2025-11-07

How to enable WebP image format in AnQiCMS to improve image loading speed and display efficiency?

Enable WebP image format in AnQiCMS: Optimize loading speed and display efficiency In today's digital age, website loading speed is one of the key factors in user experience and search engine ranking.Images are an important part of a website's content, and their loading efficiency has a crucial impact on the overall performance of the page.If the image size is too large or the format efficiency is low, it will not only slow down the website loading speed, but also consume the valuable traffic of users, and even affect the performance of the website in search engines.

2025-11-07