How to implement content list filtering by custom parameters in AnQiCMS?

Calendar 👁️ 77

In AnQi CMS, flexibly displaying and filtering content is one of the core needs for website operation.As the content structure of a website becomes increasingly complex, for example, if you operate an e-commerce platform and need to filter products by color and size, or if a real estate website needs to filter housing resources by type and area, traditional classification tags may be insufficient.At this time, by using the powerful custom parameter function of Anqi CMS, it can easily realize the filtering display of content lists according to the parameters you define, greatly enhancing the user experience and the organization efficiency of website content.

Next, we will delve deeper into how to implement this feature in AnQiCMS together.

Understand the role of custom parameters in AnQiCMS.

One of the most powerful features of AnQiCMS is its flexible content model.In addition to basic fields such as article title and content, the system allows you to customize additional fields for each content model, which we call "custom parameters".For example, in a "product

These custom parameters can not only be displayed on the content detail page, but more importantly, they can be used as filtering conditions to help users quickly find the content they are interested in.A security CMS provides special template tags to allow you to easily convert these parameters into front-end operable filters.

Core tags:archiveFiltersandarchiveList

To implement custom parameter filtering of content lists on the front-end, mainly the two core template tags of Anqi CMS will be used:archiveFiltersandarchiveList.

  • archiveFiltersTagThis tag is responsible for generating the front-end filter interface.It can automatically identify the custom parameters defined in your backend content model, and convert them into clickable filter option links.When the user clicks on these links, the page URL will carry the corresponding filter parameters.
  • archiveListTag: This tag is used to retrieve and display content lists. When it is combined witharchiveFiltersWhen used together, it intelligently reads the filter parameters carried in the current page URL and automatically filters the content based on these parameters, only displaying content that meets the conditions.

Gradually implement content list filtering display

We will demonstrate how to implement content list filtering by custom parameters with a specific example.Assuming we have a 'product' content model and have added two custom fields 'material' and 'color'.

Step one: Prepare content model and custom fields

First, make sure that the AnQiCMS backend is configured with the corresponding "content model" and "custom fields".

  1. Log in to the backend: Enter the AnQiCMS backend management interface.
  2. Create or edit the content modelNavigate to "Content Management" -> "Content Model". You can edit an existing model (such as "Product Model") or create a new content model.
  3. Add custom fieldIn the editing page of the selected content model, find the "Content Model Custom Field" area, click "Add Field".
    • Example Field 1 (Material):
      • Parameter name:材质
      • Call field:material(This field name will be used for template calls and URL parameters)
      • Field type:单项选择(Assuming material is a single selection)
      • Mandatory: Set according to need
      • Default value: Enter an option per line, for example:木材/金属/塑料
    • Example Field 2 (Color):
      • Parameter name:颜色
      • Call field:color
      • Field type:多项选择(Assuming multiple colors can be selected)
      • Mandatory: Set according to need
      • Default value: Enter an option per line, for example:红色/蓝色/绿色
    • Save your content model settings.
  4. Publish or edit contentIn the 'Content Management' -> 'Publish Document' or 'Document Management', select the corresponding 'Material' and 'Color' field values for your 'Product' content.

Step two: Design the list page template

Next, we need to modify or create the product list page template. Assuming your product list page template isproduct/list.html.

Open your template file (usually located in/template/您的模板名称/product/list.html)

1. Build the filter area (archiveFilters)

At the appropriate position in the template, usearchiveFilterstags to generate the filter.moduleIdThe parameter is very important, as it tells the tag which content model's filter parameters to generate.allTextParameters can customize the text of options such as 'All' or 'Unlimited'.

{# 假设产品模型的ID是2,请根据您的实际情况修改 moduleId 参数 #}
<div class="filter-area">
    <h3>筛选条件</h3>
    {% 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="filter-option {% if val.IsCurrent %}active{% endif %}">
                    <a href="{{ val.Link }}">{{ val.Label }}</a>
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

Code analysis:

  • moduleId="2": Specify the filter being generated for the product model with ID 2.
  • allText="不限"Set when no filter conditions are selected, display the 'Unlimited' text.
  • Outer layerfor item in filtersLoop: Traverse all filterable parameter groups (e.g., 'Material', 'Color').
    • item.Name: Display the parameter name, such as 'material', 'color'.
  • Inner layerfor val in item.ItemsLoop: Traverse all optional values under each parameter group (for example, 'wood', 'metal', 'plastic').
    • val.Label: Show each option's name, such as "wood", "red".
    • val.LinkThis is the most critical part!It will generate a URL with the corresponding filter parameters.When the user clicks, the page will reload and filter the content based on the parameters in this URL.
    • val.IsCurrentA boolean value, if the current option is selected, it will betrue, can be used to addactiveStyle to highlight.

2. Show content list (archiveList)

Below the filter area, usearchiveListLabel to display content.

`twig

<h2>产品列表</h2>
{# 同样假设产品模型的ID是2。type="page" 开启分页模式,limit="10" 每页显示10条 #}
{% archiveList products with moduleId="2" type="page" limit="10" %}
    {% for item in products %}
    <div class="product-item">
        <a href="{{ item.Link }}">
            <h3>{{ item.Title }}</h3>
            {% if item.Thumb %}
            <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
            {% endif %}
            <p>描述: {{ item.Description }}</p>
            {# 调用自定义字段,注意这里直接使用我们在后台定义的“调用字段”名称 #}
            <p>材质: {{ item.material }}</p>
            <p>颜色: {{ item.color }}</p>
        </a>
    </div>
    {% empty %}
    <p>抱歉,没有找到符合条件的产品。</p>
    {% endfor %}
{% endarchiveList %}

{# 添加分页导航 #}
<div class="pagination-area">
    {% pagination pages with show="5" %}
        {# 首页 #}
        <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {# 上一页 #}
        {% if pages.PrevPage %}
        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        {% endif %}
        {# 中间多页 #}
        {% for pageItem in pages.

Related articles

How to display category thumbnails or Banner group images in AnQiCMS?

The visual presentation of website content is the key to attracting users and enhancing experience.Especially on the category page, a beautiful thumbnail or a set of eye-catching banner images can make the content clear to the user and stimulate browsing interest.AnQiCMS as a powerful content management system, provides a flexible image management and calling mechanism, allowing you to easily set and display unique visual elements for website categories.### One, Background Configuration: Add Visual Attraction to Your Categories Firstly, you need to make the corresponding configuration in the background to display images for categories in AnQiCMS

2025-11-08

How to set the website to "closed" status and display a custom prompt message in AnQiCMS?

During the operation of the website, it is sometimes necessary to temporarily close the website, whether it is for system upgrades, data maintenance, or a brief adjustment of content, AnQiCMS provides a simple and efficient shutdown feature to help us elegantly manage the temporary shutdown status of the website.This not only avoids the user from seeing an error page and affecting the experience, but also clearly conveys information and maintains the brand image. We will learn in detail how to set the website to "closed" status in AnQiCMS and display personalized prompt information.

2025-11-08

How to use Tag labels in AnQiCMS to associate and display related documents on the front end?

AnQiCMS provides powerful classification functions to organize the website structure, and also opens up new ways for deep association and multi-dimensional display of content through flexible Tag label mechanisms.Imagine that your website is like a library, with different shelves for categories, and Tag tags are like different subject keywords on books, allowing readers to find books with similar themes scattered on different shelves according to their interests.Next, let's delve into how AnQiCMS uses Tag labels to make your website content more intelligent and rich in front-end display

2025-11-08

How to display the number of views and comments for articles in AnQiCMS?

In content operation, the number of page views and comments on articles is an important indicator of the popularity and user engagement of the content.They not only provide readers with references, but also help operators to understand content performance.AnQiCMS as a powerful content management system naturally also provides a convenient way to display these real-time data, making your website content more interactive and transparent.In AnQiCMS, whether it is articles, products, or other content types, they are all uniformly referred to as "documents" (archive)

2025-11-08

How to display the visitor message form and manage the message results in AnQiCMS?

Maintaining interaction with website visitors, collecting user feedback is a very important link that each website operator attaches great importance to.Whether it is to answer doubts, collect suggestions, or provide customer service, an efficient and convenient comment system can greatly enhance user experience and operational efficiency.AnQiCMS fully understands this and provides us with a simple and efficient visitor message function, making the entire process from form display to result management easy and effortless. ### Easily Build Visitor Message Form AnQiCMS uses flexible template tags to display visitor message forms on the website frontend.

2025-11-08

How to retrieve and display details of a specific user group (such as VIP level) in AnQiCMS template?

In AnQiCMS, managing users and content, we often encounter the need to display different information based on the user's identity (such as VIP level).The powerful template engine and user group management function of AnQiCMS makes it very intuitive and efficient to achieve this goal. Today, let's discuss how to retrieve and flexibly display detailed information of specific user groups in the AnQiCMS template, such as the name of the VIP level.

2025-11-08

How does AnQiCMS filter or replace external links in content to standardize display?

External links contained in website content, if not managed properly, may have a negative impact on the website's search engine optimization (SEO) effect, user experience, and even the quality of the content.AnQiCMS as a comprehensive content management system, provides a series of powerful and flexible tools to help you effectively filter or replace external links in the content, ensuring the standardized display of website content.

2025-11-08

How to generate random text of a specified length as placeholder content in AnQiCMS template?

## Generate random text of a specified length as placeholder content in AnQiCMS template During website development and content operation, we often encounter scenarios where we need to fill in placeholder content (Placeholder Content).Whether it is designing a new template, testing page layout, or giving an initial preview when the content is not fully ready, placeholder text can help us quickly build prototypes, intuitively evaluate the visual effects, and do not need to wait for the real content to be filled in.

2025-11-08