How to implement multi-condition filtering on a product list or article list page and display the filtered results?

Calendar 👁️ 84

In a content management system, providing users with flexible multi-condition filtering functions is a key factor in improving website usability and user experience.Whether it is an e-commerce website product list or an article classification page of a content portal, users hope to quickly locate the content they are interested in.AnQiCMS (AnQiCMS) leverages its powerful content model and template tag system, allowing you to easily meet this requirement and intuitively display the filtered results.

1. Lay a foundation: define content model and custom fields

All filtering functions rely on data. The first step in implementing multi-condition filtering in Anqi CMS is to define the corresponding custom fields in the content model.These fields will be used as your filtering criteria.

You can go to the "Content Management" backend to find the "Content Model" option.The AnQi CMS provides the 'Article Model' and 'Product Model' by default, and you can also create new content models according to your business needs.After entering the corresponding model editing page, in the "Content Model Custom Fields" area, you can add new fields.

Suppose you are running a real estate information website and need to filter according to 'property type' (such as residential, commercial, apartment) and 'floor area'. You can set up custom fields like this:

  • Field 1: House Type
    • Parameter Name: House Type (for backend recognition)
    • Field call (FieldName):housing_type(This name is crucial, used by front-end template and URL parameters)
    • Field type: Single selection (or drop-down selection)
    • Default valueEnter an option per line, for example: Residential, Commercial, Apartment, Villa
  • Field two: Floor Area
    • Parameter NameFloor Area
    • Field call (FieldName):area_size
    • Field typeDropdown selection
    • Default valueFor example: Under 50 square meters, 50-80 square meters, 80-120 square meters, Over 120 square meters

After defining the field, you can fill in the corresponding 'house type' and 'floor area' information when publishing articles or products.

2. Build the filter interface: usearchiveFiltersTag

Once we have this data foundation, the next step is to display the filter options on the front-end page. Anqi CMS provides a very convenientarchiveFiltersThe label can help you dynamically generate these filtering conditions. This label is usually used in the sidebar or top area of product list pages or article list pages.

archiveFiltersLabels will automatically read the custom fields defined in your content model and generate filter links. You need to place it in your list template file (such as{模型table}/list.html).

This is an example of building a filter interface code:

{# 假设这是您的列表页模板(例如:archive/list.html) #}
<div>
    <h3 style="font-size: 20px; margin-bottom: 15px;">房产筛选</h3>
    {% archiveFilters filters with moduleId="1" allText="不限" %}
        {% for item in filters %}
        <div style="margin-bottom: 20px;">
            <strong style="display: block; margin-bottom: 8px;">{{ item.Name }}:</strong>
            <ul style="list-style: none; padding: 0;">
                {% for val in item.Items %}
                <li style="display: inline-block; margin-right: 10px; padding: 5px 10px; border: 1px solid #eee; border-radius: 4px; {% if val.IsCurrent %}background-color: #007bff; color: white; border-color: #007bff;{% endif %}">
                    <a href="{{ val.Link }}" style="text-decoration: none; color: inherit;">{{ val.Label }}</a>
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

Several key points need to be paid attention to:

  • moduleId="1"Here is the1Represents the article model. If your filter is for the product model, then it might bemoduleId="2"Or it is the ID of the custom model you have created. You can view each model's ID on the "Content Model" page in the background.
  • allText="不限"This is the display text for the 'All' or 'Unlimited' option set for each filtering dimension. Clicking on it will remove the filtering condition for that dimension.
  • filtersVariable:archiveFiltersThe label will organize all generated filter conditions into a namedfilters.
  • item.Name: Display the parameter name of the custom field (for example, "House Type").
  • item.ItemsAn array that includes all the options under the filter condition.
  • val.LabelDisplays the text of each filter option (e.g., 'Residential').
  • val.LinkThis is the most important part. It will automatically generate a URL with the corresponding filter parameters. When the user clicks, the page will jump to a new URL with the filter parameters.
  • val.IsCurrentA boolean value that will be true if the current option is selected.trueYou can use it to add style to the selected filter condition.activeTo provide visual feedback to the user.

3. Display filtering results: CombinearchiveListTag

After the user clicks the filter condition, the page needs to display the matching results. Fortunately, the Anqi CMS'sarchiveListThe tag is very smart, it automatically reads the query parameters from the current URL and filters the content accordingly. This means you do not need toarchiveListExtra filtering logic is written in the tag, it will bearchiveFiltersseamlessly connected with the generated URL.

In the same list template, directly below the filter area, you can place the display code for the content list:

{# 列表内容展示 #}
<div style="margin-top: 30px;">
    <h3 style="font-size: 20px; margin-bottom: 15px;">筛选结果</h3>
    {% archiveList archives with moduleId="1" type="page" limit="10" %}
        {% for item in archives %}
        <div style="border: 1px solid #ddd; padding: 15px; margin-bottom: 15px; border-radius: 5px;">
            <a href="{{ item.Link }}" style="text-decoration: none; color: #333; display: flex; align-items: center;">
                {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" style="width: 100px; height: 75px; object-fit: cover; margin-right: 15px; border-radius: 3px;">
                {% endif %}
                <div>
                    <h4 style="margin: 0 0 8px 0; color: #007bff;">{{ item.Title }}</h4>
                    <p style="margin: 0 0 5px 0; color: #666;">{{ item.Description|truncatechars:100 }}</p>
                    <div style="font-size: 13px; color: #999;">
                        <span>分类: {% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        <span style="margin-left: 10px;">发布时间: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                        <span style="margin-left: 10px;">浏览量: {{ item.Views }}</span>
                    </div>
                    {# 这里可以展示自定义字段,例如“房屋类型”和“建筑面积” #}
                    {% archiveParams params with id=item.Id %}
                        {% for param in params %}
                            {% if param.FieldName == 'housing_type' %}
                                <span style="margin-left: 10px; font-size: 13px; color: #999;">房屋类型: {{ param.Value }}</span>
                            {% elif param.FieldName == 'area_size' %}
                                <span style="margin-left: 10px; font-size: 13px; color: #999;">建筑面积: {{ param.Value }}</span>
                            {% endif %}
                        {% endfor %}
                    {% endarchiveParams %}
                </div>
            </a>
        </div>
        {% empty %}
        <p style="text-align: center; color: #888;">没有找到符合条件的房产信息。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

Description of key parameters:

  • moduleId="1"Similarly, specify the document list of the content model to be retrieved.
  • type="page"This parameter tells the system that we want to display a paginated list, used in conjunction with the pagination tags.
  • limit="10": Display 10 items per page.
  • archivesVariable:archiveListTags will store the filtered content toarchivesthe variable.
  • item.Link: Link to content details.
  • item.Title: Content title.
  • item.Description: Content summary.
  • item.Thumb: Thumbnail of the content. *

Related articles

How to display custom additional field content on the detail page?

One of the core strengths of AnQiCMS is its flexible content model feature.It allows us to add various unique custom fields to content based on different business scenarios, such as products, services, events, etc.These custom fields greatly enrich the expression of content, making our website content more professional and meet the needs.But with these additional fields, how can they be presented elegantly on the front-end detail page?

2025-11-08

How can AnQi CMS automatically replace keywords to display article or product content?

In content operations, we often need to ensure that specific keywords in articles or product descriptions are consistent, even automatically associated with related pages, which is crucial for SEO optimization and improving user experience.But manually modifying one by one takes time and is prone to errors, especially when the content of the website is massive, it is also a huge challenge.Anqi CMS knows this, and therefore provides us with a very practical feature, that is, the automatic replacement and display of keywords in articles or product content.This feature can intelligently identify the keywords or phrases you preset and automatically replace them with the specified text or link

2025-11-08

How to determine whether the current item is the first or last in a looped article list so that special styles can be displayed?

In website content management, it is often encountered that there is a need: we hope that the first or last element of the article list, product list, or other data list can have special styles, such as the first article title being particularly prominent, or the last product detail not having a bottom separator line.This not only helps to highlight the key points, but also makes the visual effect of the page more hierarchical.AnQiCMS (AnQiCMS) powerful template engine provides us with a simple and efficient way to meet these customization needs.In Anqi CMS template system, we usually use `{% for ...

2025-11-08

How to define and temporarily store variables in a template for easy content display and reuse?

When building a website, we often encounter situations where we need to repeat certain information or adjust content flexibly according to different contexts.If each time is hard-coded, it is not only inefficient but also quite麻烦 to maintain later.AnQiCMS (AnQiCMS) fully understands this, its template system provides various flexible ways to define and temporarily store variables in templates, thus achieving convenient display and efficient reuse of content.Why do you need to define and store variables in templates?

2025-11-08

How to safely output content containing HTML tags in a template and prevent them from being escaped by the browser?

In website operation, we often need to display information with rich formatting and media content, such as carefully edited article details, product introductions, or customized pages.This content often contains HTML tags, such as image tags `<img>`, link tags `<a>`, paragraph tags `<p>` and so on.However, if you directly output this content to a web page, you may find that it does not render as expected, but rather displays the HTML tags as plain text, greatly affecting the user experience and the beauty of the page.

2025-11-08

How to extract a part of a long string or HTML content and display an ellipsis at the end?

In website content operation, we often encounter such situations: the article list page needs to display the summary of the content, the product detail page needs to show a brief introduction, or in some special modules, we need to extract a part of the long text or content containing HTML tags, and add "..." at the end to prompt the user that the content is not complete.This not only effectively saves page space and keeps the layout neat, but also improves the reading experience and attracts users to click to view the full content.To achieve such a function, if it were to be manually截取 each time, it would undoubtedly consume a lot of time and effort.Fortunately

2025-11-08

How to format user input plain text content (including newline characters) into HTML paragraphs and newline characters for display?

In website content management, we often encounter such needs: when users input a block of plain text content in the background, it often contains some natural paragraphs and line breaks. We hope that these paragraphs and line breaks are rendered correctly on the website front-end as HTML paragraph tags (`<p>`) and line break tags (`<br/>`), rather than being compressed into a blob or ignored by the browser.AnQi CMS provides a very convenient and powerful template filter to solve this problem, allowing plain text content to be presented elegantly on the web.

2025-11-08

How to convert timestamp data stored in the background into a readable date and time format for display?

When managing website content in Anqi CMS, we often encounter situations where we need to display dates and times.However, the time information stored in the background database is usually in the form of timestamps, which is very efficient for machine processing, but difficult for users to read directly.For example, you might see a string like `1609470335`, which represents a specific moment, but we want it to be displayed in a more friendly format like "2021 January 1 at 12:25:35".fortunately

2025-11-08