How to add multi-dimensional parameter filtering function for the product list page in Anqi CMS and display the filtering results?

Calendar 👁️ 65

In modern e-commerce and content display websites, providing multi-dimensional parameter filtering functions for product lists has become a key factor in improving user experience and conversion rates.Visitors can quickly locate the products they need based on their own needs, which not only saves time but also greatly improves the usability of the website.For users of AnQiCMS, it is not difficult to achieve such a function, the built-in powerful functions and flexible template tags make the whole process intuitive and efficient.

This article will deeply explore how to add multi-dimensional parameter filtering functionality to the product list page in Anqi CMS and clearly display the filtering results.We will start from the background configuration of product properties and gradually explain to the construction of the front-end template, ensuring that you can easily get started and create a fully functional product display page.

Understand the multi-dimensional filtering mechanism of AnQi CMS

The Anqi CMS can easily achieve multi-dimensional filtering, the core lies in its "flexible content model" and "custom field" functions.You can create dedicated content models for different types of content (such as products, articles, services, etc.) and add various custom fields to these models.These custom fields are the foundation of our multi-dimensional filtering.

After you define filterable properties (such as color, size, material, brand, etc.) for products in the background, Anqi CMS provides two key template tags to work together:

  1. archiveFiltersTagIt is responsible for automatically generating a series of filter link conditions based on the product model you define and its custom fields. These links will intelligently attach filter parameters to the URL.
  2. archiveListTagThis tag is used to get the product list. When the URL contains byarchiveFiltersgenerated byarchiveListIt will intelligently read these parameters and return product data that meets the conditions.

This mechanism allows us to avoid writing complex backend logic, just by using simple backend configuration and front-end template tags, we can achieve powerful multi-dimensional filtering functions.

Backend configuration: Define filterable properties for products

To add a filter function to the product list, you first need to define the corresponding filterable properties for your product model in the Anqi CMS backend.

  1. Enter content model management: Log in to the Anqi CMS backend, navigate to "Content Management" -> "Content Model".
  2. Select or create a product model: Usually, anqicms will integrate a "product model".If you need more fine-grained management, you can also create a new product model.Click to enter the product model editing page where you want to add the filter function.
  3. Add custom fieldHere, you will see the existing fields of the model and the "Content Model Custom Fields" area. Click "Add Field" to add filterable properties to your product.
    • Parameter NameThis is the Chinese name of the field, for example, 'Color', 'Size', 'Material'.
    • Field invocationThis is the English identifier used when calling the field in the template, for example,color/size/materialMake sure to use lowercase English letters.
    • Field typeThis step is crucial, as it determines the form of the filtering conditions.
      • Single choice/dropdown selection: The product properties are mutually exclusive, for example, 'Color: Red, Blue, Black'. The user can only choose one.
      • Multiple selections: Suitable for product properties that can be multiple, such as 'Features: Waterproof, sun protection, abrasion resistance'. Users can select multiple options.
    • Default valueFor single-choice, multiple-choice, or dropdown fields, you need to enter all possible options here, one per line. For example, if the field is "Color", you can enter the default value as:
      
      红色
      蓝色
      白色
      黑色
      
      These options will become specific values in the front-end filter conditions.
    • Mandatory?: Decide according to your business requirements.
    • Save the custom fields you add.

After completing the customization of the field settings, when you add or edit products in the background, you can fill in these newly defined attribute values for each product.These property values will become the data source for front-end filtering.

Front-end template: Build the filter interface and result display.

After the background configuration is completed, the next step is to modify your product list page template, usually this template file might beproduct/list.htmlor a custom list template you have created.

Step 1: Generate filtering conditions

In the product list page template, find the location where you want to place the filter conditions (usually at the top or sidebar of the product list). UsearchiveFilterstags to generate filter conditions:

{# 假设您的产品模型ID是2,并且您希望“全部”选项显示为“不限” #}
<div class="product-filters">
    {% archiveFilters filters with moduleId="2" 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="{% if val.IsCurrent %}active{% endif %}">
                    <a href="{{ val.Link }}">{{ val.Label }}</a> {# val.Link 包含了筛选参数的URL #}
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

Code description:

  • moduleId="2": Replace it with yourProduct Model IDYou can find the corresponding ID in the background "Content Model".
  • allText="不限": Set the display text for the "All" option, if it is set tofalsethen the "All" option will not be displayed.
  • filtersThis isarchiveFiltersAn array object returned by the label, containing all filterable dimensions (such as color, size).
  • item.Name: Display filter dimensions (such as "color").
  • item.Items: This is all the options under the current filtering dimension (such as "red", "blue"), and it is also an array.
  • val.Label: Display the name of the specific option (such as "red").
  • val.LinkThis is the key! Anqi CMS will automatically generate a URL containing the corresponding filter parameters. When the user clicks on this link, the page will refresh with new filter parameters.
  • val.IsCurrent: Determine if the current option is selected, can be used to addactiveClass name, so that it can be highlighted by CSS for the selected filter condition.

Step 2: Display the filter results

After generating the filtering conditions, the next step is to display the product list based on these conditions. You need to usearchiveListtags and make sure that itstypethe parameter to"page"So that it can respond to filtering parameters in the URL and perform pagination.

<div class="product-list">
    {% archiveList archives with type="page" moduleId="2" limit="12" %} {# 每页显示12个产品 #}
        {% for product in archives %}
        <div class="product-item">
            <a href="{{ product.Link }}">
                {% if product.Thumb %}<img src="{{ product.Thumb }}" alt="{{ product.Title }}" />{% endif %}
                <h3>{{ product.Title }}</h3>
                <p>{{ product.Description }}</p>
                {# 假设您有自定义字段:价格 price,颜色 color #}
                {# 您也可以通过archiveParams标签循环显示所有自定义字段 #}
                {% archiveDetail productPrice with name="price" id=product.Id %}<p>价格: {{ productPrice }}</p>{% endarchiveDetail %}
                {% archiveDetail productColor with name="color" id=product.Id %}<p>颜色: {{ productColor }}</p>{% endarchiveDetail %}
            </a>
        </div>
        {% empty %}
        <p class="no-results">没有找到符合条件的产品。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

Code description:

  • moduleId="2"Replace it with your product model ID.
  • type="page":Very importantThis tellsarchiveListGo to parse the query parameters in the URL and perform pagination processing.
  • limit="12": Set the number of products displayed per page.
  • productThis isarchiveListLoop through each product object, you can access its properties like a regular product listproduct.Title/product.Link/product.Thumbetc.).
  • Display of custom fields: For custom fields, you can usearchiveDetailLabel to get individually, or usearchiveParamsLabel to display all custom parameters in a loop. For example,{% archiveDetail productPrice with name="price" id=product.Id %}Will get the current product(id=product.Id) namedpricecustom field value.

Step 3: Add Pagination Function

Pagination is essential when there are many products. CombinearchiveListoftype="page"the pattern, you can usepaginationtags to easily add pagination:

<div class="pagination-area">
    {% pagination pages with show="5" %} {# 最多显示5个页码按钮 #}
    <ul class="pagination-list">
        {% if pages.FirstPage %}<li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a></li>{% endif %}
        {% if pages.PrevPage %}<li class="prev"><a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a></li>{% endif %}
        {% for item in pages.Pages %}
        <li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{ item.Link }}">{{ item.Name }}</a></li>
        {% endfor %}
        {% if pages.NextPage %}<li class="next"><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>{% endif %}
        {% if pages.LastPage %}<li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a></li>{% endif %}
    </ul>
    {% endpagination %}
</div>

Code description:

  • pagesThis ispaginationThe label provides us with the pagination information object.
  • show="5": Controls how many page number buttons are displayed at one time in the pagination area.
  • pages.FirstPage.Link/pages.PrevPage.LinkThese links will automatically carry the current filter parameters to ensure that the filter conditions will not be lost when the user clicks on the pagination.

Optimization and practical suggestions

  • Design a user-friendly filter interface:The visual design of the filtering conditions is very important. Use CSS to highlight the currently selected conditions and provide a "Clear all filters" button (usually just

Related articles

How to display the current year or time in a specific format in AnQi CMS template?

In website operation, it is a common requirement to flexibly display the current year or format specific time, whether it is the automatic update of the year in the copyright statement or the clear display of the publication time on the article detail page.AnQiCMS provides two main ways to meet these needs, they are both simple to use and follow the elegant time handling of the Go language.### Method 1: Directly retrieve and display the current year or time (`{% now %}` tag) When you need to directly retrieve and display the current year or the current time down to the second in the template

2025-11-08

Does AnQi CMS provide an integrated JS statistics code calling tag for easy display on the page?

When using AnQiCMS, many users are concerned about how to conveniently integrate third-party JavaScript statistical codes into web pages, such as Baidu Statistics, Google Analytics, and so on.About this, AnQiCMS indeed provides built-in mechanisms and flexible template tags, allowing you to easily call and display these statistics codes on your website.### Using built-in JS code to call tags AnQiCMS to meet the needs of website operators to integrate third-party scripts

2025-11-08

How can AnQi CMS use the 'time factor' feature to display future published content?

How to efficiently and strategically publish content in today's fast-paced content environment is a question that every content operator is thinking about.Maintain the consistency and foresight of content publication, which can not only enhance the user experience but also effectively promote brand communication and search engine optimization.AnQi CMS deeply understands this, and its 'Time Factor' feature was born for this very purpose, providing content creators and operation teams with a precise tool to control the timing of content release.## Precise Planning: The Foundation of Content Operation We have all faced such a situation: writing an精心 prepared article

2025-11-08

How can AnQi CMS templates inherit parent templates and rewrite specific block content to customize display?

In Anqi CMS, the template system provides a powerful and flexible mechanism that allows users to efficiently customize the layout and content display of the website.Among them, "inheriting the parent template and rewriting specific block content" is a key function to achieve personalized design and maintain consistency with the overall style of the website. ### Core Concept: Say goodbye to repetition, embrace inheritance Imagine that the header, footer, sidebar, and other elements of a website are fixed and unchanged on almost every page. If there is no template inheritance mechanism, we may need to repeat this common code in each page template, which increases the difficulty of maintenance

2025-11-08

How does AnQi CMS filter and display content based on the document's Flag attribute (such as headline, recommended)?

In AnQiCMS (AnQiCMS) content management system, effectively organizing and displaying content is the key to enhancing website attractiveness and user experience.Among them, the Flag attribute (recommended attribute) function of the document, as if marking the content with a special 'mark', allows you to flexibly filter and highlight important or specific types of content according to your operational needs.What is the document Flag attribute? The document Flag attribute, also known as the recommendation attribute, is a content classification and display mechanism provided by AnQi CMS.

2025-11-08

How to manage and display custom page Banner carousel in Anqi CMS?

In website operation, a beautiful page banner carousel is a key element to attract visitors' attention, convey important information, and enhance brand image.AnQiCMS provides a flexible and intuitive way to manage and display these visual contents, whether you want to set up a Banner for the homepage, a specific page, or a category page, it can be easily achieved.### Manage Custom Banner Carousel AnQi CMS allows you to set exclusive banners for different content types, mainly divided into banners for specific pages

2025-11-08

How to implement the like function for comments in Anqi CMS and update the display of likes in real time?

In website operation, user interaction is a key link in enhancing community activity.The like comment feature not only encourages user participation, but also helps website administrators identify popular comment content.For websites using AnQiCMS, to implement this feature and update the like count in real time, it can be done through the built-in template tags and a bit of front-end JavaScript code.### Comment Function Basics: How to Display Comment Lists The core of the comment function in AnQi CMS lies in the `commentList` template tag

2025-11-08

How to safely output rich text content containing HTML tags in Anqi CMS template?

In website operation, rich text content is widely used in articles, product introductions, and single-page scenarios due to its rich expression, such as inserting images, custom font styles, and tables.AnQi CMS as an efficient content management system also fully supports the editing and storage of various rich text content.However, rich text content, while bringing convenience, also hides a non-negligible security challenge - how to safely output this content containing HTML tags in templates to prevent potential cross-site scripting attacks (XSS)

2025-11-08