How to build a dynamic filter using the `archiveFilters` tag to display documents that meet specific conditions?

Calendar 👁️ 64

How to help users quickly find the information they are interested in when managing a content-rich website, improve the user experience, is a challenge that every content operator needs to face. AnQiCMS (AnQiCMS) understands this need and provides strongarchiveFiltersTags, allowing you to easily build dynamic filters, providing flexible and diverse search methods for website content.

Dynamic filter, as the name implies, is to automatically generate filtering conditions for users to choose from based on different attributes of the content.It is not just a simple classification navigation, but also an intelligent retrieval tool that goes deep into the details of the content.Imagine, a real estate website user wants to filter housing listings that are 'residential' type and have an area of 90-120 square meters, or a product website user wants to find 'red' T-shirts with patterns. These complex requirements can be easily resolved through dynamic filters.AnQi CMS'sarchiveFiltersTags, which is the key to realizing this function.

Building such a filter is not complicated. You first need to define various custom fields in the content model of Anqi CMS.For example, for a real estate model, you can add fields such as 'house type', 'area', 'price range', etc;For the product model, it can be things like 'color', 'style', 'material', etc.When these custom fields are configured as filter parameters,archiveFiltersTags can exert their magic.

UsearchiveFiltersWhen labeling, it usually starts like this:{% archiveFilters filters with moduleId=1 allText="全部" %}.

here,moduleIdThe parameter is very important, it specifies which content model (such as article model, product model, etc.) you want to filter the documents. Different models have different custom fields, throughmoduleIdThe system can accurately retrieve the filtering parameters of the corresponding model. However,allTextThe parameter allows you to customize the text content of default options such as “Show All” or “Unlimited”, and even set them to not display. If your website has enabled multi-site management features,siteIdParameters can help you specify the data to be retrieved from a specific site.

WhenarchiveFiltersAfter the tag is executed, it will generate a variable namedfilters(You can customize this variable name). ThisfiltersA variable is an array object that contains detailed information for each selectable parameter.In the template, you can iterate over these filter parameters through a loop to dynamically display them on the page.

goes deep intofiltersThe structure of each variableitemrepresents a specific filtering dimension, such as "house type" or "area". Eachitemincludes the following key information:

  • item.Name: This is the display name of the filter, which the user will see on the page, for example, 'House Type'.
  • item.FieldNameThis is the actual field name defined in the background content model, which is the basis for the system to identify and filter dimensions.
  • item.Items: These are all the selectable values under the current filtering dimension, and it is also an array.

Next, we need toitem.ItemsPerform a second loop to display specific options under each filtering dimension, such as "Residential", "Commercial" or "Small apartment", "Large apartment". In this loop, eachvalThe object provides:

  • val.Label: This is the displayed text for the filter option, what the user clicks.
  • val.LinkThis is an AnQi CMS automatically generated complete URL, clicking it will automatically apply the filter condition and refresh the content list.The system will intelligently add the filter conditions in the form of query parameters to the URL.
  • val.IsCurrentThis is a boolean value used to indicate whether the current option has been selected.This is very useful when adding styles (such as highlighting) to the currently selected filter conditions, which can significantly enhance the user interface friendliness.

Combine all this, and we can build a complete and interactive filtering interface in the template. For example, in a property document list, you can first usearchiveFiltersTag generation filter conditions, then combinearchiveListTag (configurationtype="page"Support pagination and URL parameter filtering)paginationLabels to display the filtered document list and pagination navigation. When the user clicks on a filter option,val.Linkit will redirect the page to a URL with the corresponding query parameters,archiveListThe tag will automatically recognize these parameters and only display documents that meet the conditions.

In this way, the Anqi CMS'sarchiveFiltersTags greatly simplify the development of dynamic filtering functions. They not only improve the organization and discoverability of website content, but also allow users to obtain the information they need more efficiently and accurately, thereby significantly enhancing the overall user experience.Use this tag flexibly, and it will make your website content operation twice as effective.


Frequently Asked Questions (FAQ)

  1. Ask: I have added custom fields to the content model in the background, but whyarchiveFiltersWhy are these fields not displayed as filter conditions under the tags?

    • Answer:Please check whether you have set the custom field created in the content model to 'filterable'. Only fields that are explicitly marked as filterable,archiveFiltersTags can identify and use them as dynamic filtering conditions. In addition, make sure youarchiveFiltersThe label is correctly specifiedmoduleIdto associate it with the correct custom content model.
  2. Question:archiveFiltersgenerated filtering link (val.LinkDoes it look like a normal URL with parameters, will it affect my website SEO?

    • Answer: archiveFiltersThe generated links usually contain query parameters such as?field=value), this is something that search engines can understand and capture in many cases. Although Anqi CMS supports static rule configuration for SEO-friendly URLs.archiveFiltersThe URL generated is parameterized, but you can combine it with the background pseudo-static rule management feature for optimization. If there are too many filtering conditions causing the URL to be too long or repetitive, consider usingrel="canonical"Tag to specify the standard URL of the content, avoiding SEO weight dispersion.
  3. Question: Can I use multiplearchiveFiltersTags to independently filter different content lists?

    • Answer:Technically possible, but you need to be aware of variable name conflicts. If you use multiplearchiveFilterstags, you need to assign different variable names to each tag (for examplefilters1/filters2), to avoid overlapping. At the same time, eacharchiveListtag also needs to specify its screening parameter source, or ensure that itsmoduleId/categoryIdThe correctness of the parameters, so that they can respond to their respective filters. In practice, a filter usually serves a main content list.

Related articles

How does the `archiveParams` tag display custom field data for AnQiCMS documents?

In AnQiCMS, the flexibility of website content is one of its highlights, which is attributed to its powerful content model custom field function.In addition to standard fields such as article title, content, and publication time, you can also add various custom fields according to business needs for different content models (such as articles, products), such as 'author', 'product model', 'house area', or 'service features'.These custom fields greatly enrich the expression of the website content, making it more closely aligned with practical application scenarios.So, when you tirelessly define and fill in these custom fields in the background

2025-11-07

How to dynamically set and display the page's Title, Keywords, and Description using the `tdk` tag to optimize SEO?

How to make our content better discovered by search engines and attract more potential users is a continuous challenge in website operation.Among them, the Title (title), Keywords (keywords), and Description (description) these three TDK tags are like a series of 'business cards' on our website in the search engine results page, directly affecting the user's click intention and the understanding of the search engine.AnQi CMS knows this and therefore fully considered the dynamic setting of TDK and SEO friendliness in the initial system design.<h3>Importance of TDK

2025-11-07

How to uniformly display the website's contact information, phone number, and email address with the `contact` tag?

How to efficiently manage and uniformly display a company's contact information, such as contacts, phone numbers, email addresses, and addresses, is a seemingly simple problem that often causes headaches.Imagine if this information were scattered across various pages of a website, and once an update is needed, you would have to search and modify each one individually. This is not only time-consuming and labor-intensive, but it is also prone to omissions or inconsistencies.Fortunately, AnQiCMS (AnQiCMS) provides an elegant solution - the `contact` tag, which helps us easily manage and flexibly display contact information.

2025-11-07

How to call and display the website name, Logo, filing number, and other global configuration information using the `system` tag?

Building a website in Anqi CMS, the basic information of the page, such as the website name, Logo, filing number, copyright information, etc., is an important element in forming the overall style and professionalism of the website.This information often needs to be managed uniformly and flexibly called at various corners of the website.AnQi CMS provides the `system` tag, which is like a central console that allows us to easily call and display these global configuration information.

2025-11-07

How to get and display the carousel or advertisement images on the homepage using the `bannerList` tag?

In the operation of a website, the homepage carousel or advertisement image is undoubtedly the golden area to attract visitors' attention, convey core information, and promote important content.They not only enhance the visual appeal of a website, but are also crucial for guiding user behavior and promoting content consumption.In Anqi CMS, the functions to implement and manage these carousel or ad images are all concentrated on a powerful and easy-to-use tag —— `bannerList`.

2025-11-07

How to display comments of the `commentList` tag

In website operation, article comments are an indispensable part of enhancing user interaction and activating the community atmosphere.AnQiCMS (AnQiCMS) provides us with a powerful and flexible comment management function, through the clever use of `commentList` tags, we can easily display the comments of articles on the website front-end.This article will delve into the various functions of the `commentList` tag and its practical application in templates, helping you create an interactive and user-friendly comment section.--- ### Core Tag

2025-11-07

In Anqi CMS template, how to center the product title within a fixed area?

In Anqi CMS template, centering the product title within a fixed area is a common layout requirement, which can effectively enhance the visual aesthetics and user experience of the website.Due to the similar Django template engine syntax adopted by AnQi CMS and its good support for frontend styles, we can achieve this goal by combining HTML structure and CSS styles. ### Understanding Anqi CMS Template Structure Firstly, we need to clarify how the product title is called in the Anqi CMS template.

2025-11-07

How to use the AnQiCMS `ljust` filter to align the navigation menu text to the left and fill with spaces?

AnQi CMS is an efficient and flexible content management system that provides users with rich template tags and filters, helping us easily customize all aspects of the website.Today, we will explore a practical template trick: how to use the `ljust` filter to align your navigation menu text neatly to the left and intelligently fill in spaces, thereby improving the visual consistency and user experience of the website.

2025-11-07