How to implement multi-condition filtering display of article lists (such as by price, region) in Anqi CMS?

Calendar 👁️ 68

In modern website operation, users' demand for content filtering is growing increasingly.Whether it is to find products at a specific price or to inquire about activities in a certain area, an article list that supports multi-condition filtering can greatly improve user experience and content reach efficiency.AnQiCMS (AnQiCMS) provides a convenient solution for website operators to implement complex filtering functions with its flexible content model and powerful template tags.

The foundation for building multi-dimensional content: custom fields of the content model

In Anqi CMS, the core of implementing multi-condition filtering of article lists lies in the flexible use of the "Content Model" feature.The content model allows us to define unique fields for different types of content (such as articles, products, events, real estate, etc.) based on the business needs of the website.

We need to implement filtering by "price" and "region" for real estate information websites. First, you need to configure the content model in the Anqi CMS backend. You can create a content model named "Housing" (if it has not been created yet) and then add custom fields:

  • Price (Price)This field can be set to a 'number' type for storing specific house prices conveniently.If you need to implement price range filtering, you can achieve it by cooperating with a customized input box in the template.
  • Region (Region)This field can be set to 'Single Selection' or 'Dropdown Selection' type.In the default value, you can list all supported region options, such as "ShanghaiThis way, when posting housing information, editors only need to select from the preset list.

In addition to price and location, you can also add more fields as needed, such as 'house type', 'area', 'rental method', etc., which can be met through different field types (such as multiple selection, single-line text) to lay a foundation for subsequent filtering.

Flexibly present filter options:archiveFiltersThe application of tags

With custom fields as data support, the next step is to present these filter conditions on the website front end for user selection. Anqi CMS providesarchiveFiltersTemplate label.

archiveFiltersTags can automatically read the custom fields you define in the content model, which can be used for filtering, and generate corresponding filter options and URL links. For example, if you define the "region" field for the "property" model,archiveFiltersYou can generate a list containing regional options such as "Shanghai

Using the templatearchiveFiltersyou can go throughmoduleIdThe parameter specifies the model to be filtered, ensuring it acts on the correct content type. At the same time,allTextThe parameter can customize the display text for options such as “All” or “Unlimited” to enhance user experience.archiveFiltersThe label outputs an array object that includes the names of each filtering condition, field name, and the specific options under it (including the text of the options, the link clicked, and whether the current selected state), which is convenient for building the filtering UI on the front end.

Sample code snippet (used to generate filter UI):

{# 假设我们有一个房源模型,moduleId为3 #}
<div>
    <p>筛选条件:</p>
    {% archiveFilters filters with moduleId="3" 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>
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

This code will iterate over all selectable custom fields and generate a list for each field and its options. When the user clicks on an option, the page URL will carry the corresponding filter parameters.

Accurately obtain filtered results:archiveListPowerful combination of tags

After the user clicks the filter condition, the page URL will contain something like?region=上海&price_min=1000&price_max=2000parameters. At this point, the Anqi CMS'sarchiveListTemplate tags have taken effect.

archiveListTags are used to retrieve the list of articles (or any document type). When itstypethe parameter to"page"(Indicates that this is a pagination list) It will automatically parse all query parameters from the current URL, including keyword search (qparameters) and the filtering parameters you define (such asregion/price_minAnd), and retrieve the matching content from the database according to these parameters.

This means you do not need to write complex backend code to handle the filtering logic.archiveListThe tag will automatically complete this process. It will dynamically adjust the query based on the URL parameters and return a list of articles that meet all the conditions.

Sample code snippet (combining filter UI with list display):

``twig {# This is a listing page for housing resources, moduleId is 3 #}

{# Filter condition UI part, as shown above #}

<p>筛选条件:</p>
{% archiveFilters filters with moduleId="3" 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>
            </li>
            {% endfor %}
        </ul>
    </div>
    {% endfor %}
{% endarchiveFilters %}

{# Article list display part #}

{% archiveList archives with moduleId="3" type="page" limit="10" %}
    {% for item in archives %}
    <div class="article-item">
        <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
        <p>{{item.Description}}</p>
        {# 假设您有价格和地域的自定义字段,可以直接通过item.Price和item.Region调用 #}
        <p>价格: {{item.Price}} | 地域: {{item.Region}}</p>
        <span>发布时间: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
    </div>
    {% empty %}
    <p>抱歉,没有找到符合条件的房源信息。</

Related articles

How to display different content blocks based on conditions in the AnQi CMS template?

In AnQi CMS template design, displaying or hiding content blocks based on different conditions is a key ability to achieve dynamic website effects and enhance user experience.Using the built-in template syntax and rich tag features, we can easily build flexible and versatile pages that respond to different situations.The Anqí CMS template engine adopts a syntax similar to Django, which makes conditional judgment and loop control very intuitive and easy to learn.

2025-11-08

How does the "Full Site Content Replacement" feature of AnQi CMS affect the final display of published content?

In the daily operation of website management, content updating and maintenance is a continuous and crucial aspect.AnQiCMS (AnQiCMS) understands this need and therefore provides a powerful and efficient feature - 'Full Site Content Replacement'.This feature is not a simple modification of the front-end display, but a deep and immediate modification at the database level of published content, which has a direct and comprehensive impact on the final display effect of the website content.What is the "site-wide content replacement" feature?The "All-site Content Replacement" feature of Anqi CMS, as the name implies

2025-11-08

How to get and display the list of friend links in Anqi CMS?

In website operation, friendship links (also known as friend links) are an important component for improving website authority, increasing external traffic, and promoting interaction between websites.A well-maintained list of friendship links, which can not only increase the external links of the website and have a positive effect on SEO, but also provide users with more relevant information and improve the user experience.AnQi CMS knows its importance and provides an intuitive and user-friendly backend management interface and convenient template calling method, allowing you to easily obtain and display the list of friend links. We will introduce in detail how to implement this feature in Anqi CMS.--- ##

2025-11-08

Does AnQi CMS support the display of mathematical formulas and flowcharts in article content?

In content creation, especially in technical articles, academic papers, or project documents, we often need to present complex mathematical formulas and clear flowcharts to enhance the professionalism and readability of the content.For users of AnQiCMS, this is indeed a very practical need.Then, does Anqi CMS support displaying mathematical formulas and flowcharts in article content?The answer is affirmative, and it is not complex to implement. AnQi CMS provides flexible and diverse content management methods for content creators, one of which is the built-in Markdown editor.

2025-11-08

How to set the website Logo, filing number, copyright information and other global display content in Anqi CMS?

The website's logo, filing number, copyright information, these seemingly trivial elements are the foundation of the website's professional image, brand recognition, and compliance.In Anqi CMS, managing these global display contents is much more convenient than imagined, without the need for complex code modifications, just by performing intuitive backend operations, you can easily create a professional and standardized website facade.This article will guide you step by step on how to efficiently set up and use these important global information in Anqi CMS.

2025-11-08

How can AnQi CMS automatically extract the first image in the article content to display as a thumbnail?

In website content operation, carefully selecting and setting thumbnails for each article is a routine and time-consuming task.These small images can effectively attract visitors' attention and are also the key to maintaining visual consistency on the list page and recommended positions.Anqi CMS deeply understands this, providing users with a very convenient feature: automatically extracting the first image from the article content to display as a thumbnail. ### Core Feature Unveiling: Automatic Thumbnail Extraction Mechanism Anqi CMS showcases its user-friendly side in content management.When you write or edit an article, if you have not manually uploaded a specific thumbnail

2025-11-08

How to prevent content scraping in Anqi CMS and add watermark display to images?

In the era where content is king, the value of original content is self-evident, however, the problems of content plagiarism and image theft are becoming increasingly rampant.For website operators, how to effectively protect their hard work, prevent malicious collection of content, and add exclusive identification to images is a key link in maintaining brand image and content rights.AnQiCMS (AnQiCMS) is well aware of this pain point and has built-in features to address these challenges.

2025-11-08

How does the Anqi CMS scheduled publishing function control the display time of article content?

In content operation, the timing of content release is often closely related to the propagation effect.To help website administrators plan and distribute content more flexibly and efficiently, AnQiCMS (AnQiCMS) provides a very practical feature - scheduled publishing.This feature allows you to precisely control the display time of article content on the website, realizing the automation and intelligence of content publishing.

2025-11-08