How to implement multi-condition (such as custom parameters) filtering function on the document list page?

Calendar 👁️ 80

In AnQi CMS, implementing a multi-condition filtering function on the document list page, especially one based on custom parameters, is crucial for enhancing user experience and helping users quickly find the content they need.AnQi CMS relies on its flexible content model and powerful template tag system, making this feature highly efficient and intuitive.

The entire process can be divided into several core steps: First, define your content model and custom filter fields in the background; second, build the display interface for filter conditions in the template; finally, present the filtering results in the document list using list tags.


Step 1: Preparation: Define content model and custom fields

To implement filtering based on custom parameters, we first need to ensure that the content itself contains these parameters available for filtering.AnQi CMS provides flexible content model management functions, allowing users to customize fields according to business needs.

  1. Enter content model management: Log in to the Anqi CMS backend, navigate to "Content Management" -> "Content Model".Here, you can choose to modify the existing content model (such as 'article model' or 'product model'), or create a completely new model.

  2. Add custom fieldIn the content model editing page, find the "Content Model Custom Fields" area. Click add field, you need to configure the following key items:

    • Parameter NameThis is the display name of the field, for example, 'House Type', 'Location', or 'Price Range'.
    • Field invocationThis is the unique identifier used to call this field in the template, usually recommended to use letters, such ashouseType/region/priceRange. This field name will be used directly as a URL query parameter.
    • Field typeThis is crucial. For easy filtering, we usually choose types such as 'single selection', 'multiple selection', or 'drop-down selection'.These types can provide preset options to generate standardized filtering conditions.
    • Default valueIf the 'Single Choice', 'Multiple Choice' or 'Dropdown Selection' type is selected, you need to fill in the option values here.Each option takes up a line, the system will automatically parse it into an independent filter item.For example, in the "House Type" field, you can fill in "Residential", "Commercial", "Villa", and so on.
    • Mandatory?: Set according to your business requirements.

By following these steps, you have added custom parameters with filtering potential to the content model.For example, add fields such as 'house type' (single selection, options: one-bedroom, two-bedroom, three-bedroom) and 'decoration' (single selection, options: finished, raw, simple decoration) to the real estate model.


II. Core Function: Build a filter condition display interface.

After defining the custom parameters, the next step is to display these filtering conditions on the front-end page for user selection. This is mainly provided by the Anqi CMS.archiveFiltersTag it to complete.

  1. Choose a suitable template file: Usually, the template file corresponding to the document list page is{模型table}/list.htmlor{模型table}/list-{文档分类ID}.html. In this file, you need to insert the template code for the filter conditions.

  2. UsearchiveFiltersTag:archiveFiltersTags are specifically used to generate a list of filtering conditions based on custom model parameters.It will traverse the custom fields suitable for filtering that you define for the specified model, and generate corresponding filter links for each field option.

    It supports the following parameters:

    • moduleIdSpecify the content model ID to be filtered. For example,moduleId="1"represents the article model,moduleId="2"Represents a product model. If the current page is already a list page of a model, this parameter can be omitted, and the system will automatically identify.
    • allText: Used to set the display text for the 'All' option of each filtering condition item, such as 'No limit', 'All', etc. If you do not want to display it, you can set it tofalse.

    archiveFiltersThe label will return an array object containing all filtered fields and their options. Each field object includesName(parameter name),FieldName(the called field) as well asItems(all options of the field).ItemsEach option in the array also includesLabel(Option display text),Link(Filter link) andIsCurrent(Whether currently selected) and other information.

  3. Build a filter interface exampleThe following is a typical code structure of a filter interface:

    <div class="filter-area">
        {% 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-item {% if val.IsCurrent %}active{% endif %}">
                    <a href="{{ val.Link }}">{{ val.Label }}</a>
                </li>
                {% endfor %}
            </ul>
            {% endfor %}
        {% endarchiveFilters %}
    </div>
    

    This code will iterate over all filterable custom fields and generate one for each field (such as "house type", "decoration"):<ul>List, and display all options for this field. Each option will generate a link, which, when clicked, will navigate to the current list page with the corresponding query parameters, as well asIsCurrentProperties will help us add to the current selected filter conditionsactiveto highlight the class.


3. Linked display: Make the filter results take effect in the document list.

After the user clicks the filter link, the URL will include parameters like?houseType=三居室&decoration=精装修. At this point, the document list needs to recognize and respond to these parameters, only displaying documents that meet the criteria.

  1. UsearchiveListTag: On the document list page, we usearchiveListtags to retrieve and display document data. The key is to settype="page"Parameters, in this wayarchiveListTags can automatically parse query parameters from the URL and apply them as filtering conditions to document queries.

    archiveListTags support various parameters, the most important of which is:

    • type="page"Tell the label that this is a paginated list and it will automatically handle the filtering parameters and page numbers in the URL.
    • moduleIdSpecify the model to which the document to be displayed belongs.
    • limit: Controls the number of documents displayed per page.
    • Other parameters such ascategoryId/order/q(Search keywords) etc. can also be used as needed.
  2. Build an example of a document list:

    <div class="document-list">
        {% archiveList archives with type="page" moduleId="1" limit="10" %}
            {% for item in archives %}
            <div class="document-item">
                <a href="{{ item.Link }}">
                    <h3>{{ item.Title }}</h3>
                    <p>{{ item.Description }}</p>
                    <div class="meta">
                        <span>分类: {% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        <span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                        <span>浏览量: {{ item.Views }}</span>
                    </div>
                </a>
            </div>
            {% empty %}
            <p>没有找到符合条件的文档。</p>
            {% endfor %}
        {% endarchiveList %}
    </div>
    
    {# 分页导航 (需配合 type="page" 使用) #}
    <div class="pagination-area">
        {% pagination pages with show="5" %}
            {# 分页逻辑代码,此处省略,可参考文档 tag-pagination.md #}
            <!-- 示例: 首页、上一页、页码、下一页、末页链接 -->
        {% endpagination %}
    </div>
    

    By settingtype="page",archiveListWill automatically convertarchiveFiltersGenerated, and the query parameters passed after clicking on the URL are recognized as filter conditions.It will filter the documents based on these parameters and only display the documents that meet the conditions.At the same time, it will also pass the current page information topaginationTag, implement correct pagination under filtering conditions.


4. Integration and Optimization: An example of a complete filtering page.

Integrate the code for displaying the above filtering conditions and the document list display into the same template file (for exampleproduct/list.html) to form a complete multi-condition document list page.

For example, on a real estate website list page, users can select conditions such as 'house type', 'area', 'price range', and so on to filter:

”`twig {# Filtering conditions display area #} <div class=”

Related articles

How to implement keyword search and display results on the document list page?

How to help visitors quickly and accurately find the information they need in the face of increasingly large amounts of website content is the key to improving user experience and website value.AnQiCMS (AnQiCMS) is deeply proficient in content management, providing us with a powerful and flexible keyword search mechanism that allows the document list page to easily implement keyword search and elegantly present the results.

2025-11-08

How to filter and display a document list based on specific recommendation attributes (such as 'Headline', 'Recommendation')?

The flexible application of content recommendation properties in AnQiCMS is a key link in enhancing the visibility and user experience of website content.Whether you want to highlight important news on the homepage or recommend selected content in specific sections, AnQiCMS provides a convenient and efficient solution.This article will delve into how to filter and display document lists based on specific attributes such as 'Headlines' and 'Recommendations', helping you better manage and present website content.### Part One: Understanding Recommendation Properties and Their Settings Recommendation properties are a very practical feature in the AnQiCMS content management system

2025-11-08

How to call and display the data of the custom model field in the document?

In Anqi CMS, the flexible content model is one of its core strengths, allowing us to create various information carriers such as articles, products, and more according to different business needs and define unique properties for them.How to present the data of these customized fields in the website front-end after we have set them for the document is a major concern for many users.This article will provide a detailed explanation of this process, helping you easily master the custom model fields of Anqi CMS. ### Understanding the Value of Custom Model Fields Firstly, let's clarify the importance of custom model fields.

2025-11-08

How to display the titles and links of the previous and next documents on the document detail page?

In website content operation, it is crucial to provide readers with a smooth reading experience.If a user finishes reading a document and can easily navigate to the previous or next related content, it not only effectively extends the user's stay on the website and increases page views, but also helps search engines better understand the structure and content relevance of the website, thereby having a positive impact on SEO.AnQiCMS (AnQiCMS) has fully considered this point in the design of template functions, providing simple and powerful tags, making it easy to display the title and link of the previous and next documents on the document detail page

2025-11-08

How to set pagination for a document list and display page navigation?

In modern website operations, setting up pagination for content lists is almost indispensable.It can not only significantly improve the user's browsing experience, avoid the slow loading caused by the long content of a single page, but also help search engines better crawl and index the website content.For friends using AnQi CMS, implementing pagination for the document list and displaying page navigation is a very intuitive and powerful feature.Our AnQi CMS provides flexible template tags, allowing full control over content display.To set pagination for the document list and display page navigation in a friendly manner

2025-11-08

How to display the name of a specified category

Flexible display of category names in AnQiCMS: A comprehensive template call guide Content categories are the core of the website structure, not only helping to organize and manage massive information, but also guiding users to browse the website and improve the user experience.Whether it is an article list, product details, or side navigation, clearly displaying category names can make the content of your website more organized.

2025-11-08

How to define a string array directly in the AnQi CMS template?

In AnQi CMS template development, we often encounter the need to display some list data on the page, such as navigation menus, category tags, or some fixed options.When this data is not suitable for dynamic retrieval from the backend database, or when we just need a simple and fixed set of strings, defining a string array directly in the template is very convenient and efficient.Our Anqi CMS provides a flexible way to handle such requirements based on the Django template engine syntax.

2025-11-08

Can 'list' filter be used to define an array that includes numeric types in the AnQi CMS template?

During the development of AnQi CMS templates, we often need to handle various data, among which arrays (or lists) are commonly used to organize data.When it comes to defining an array containing different data types directly in a template, many friends may be curious whether types like numbers can also be processed and included in the `list` filter?The answer is affirmative.The `list` filter in Anqi CMS template is designed to be very flexible, it fully supports including numeric data in the defined array.

2025-11-08