How to implement the filtering function of the article list in AnQiCMS, displaying different results according to custom parameters?

Calendar 👁️ 74

How to make it easier for users to find the content they need on a website is the key to improving user experience and conversion rates.The filtering function of the article list is an important means to achieve this goal.AnQiCMS provides a flexible and powerful mechanism that allows us to easily filter and display different article list results based on custom parameters, which is very helpful for building personalized, high-efficiency content platforms.

The foundation of building a filtering function: Custom content model

To implement article list filtering based on custom parameters, first you need to understand how these 'custom parameters' are defined.The powerful 'Content Model' function of AnQi CMS is the foundation for achieving this goal.It allows us to add dedicated fields for content types such as articles, products, and so on based on actual business needs.

For example, if you are running a real estate website, in addition to basic information such as article titles, content, and categories, you may also need to add parameters such as "house type" (such as apartment, villa, shop), "area range", "number of bedrooms", and so on for each real estate introduction.In the Anqi CMS backend, we can go to the "Content Management" section under the "Content Model" part, select or create a content model (such as the "Real Estate Information" model), and then add these custom fields.Each field can be set to different types, such as single-line text, numbers, single selection, multiple selection, or dropdown, and default values can be defined.These settings will directly affect the available options for frontend filtering.

When these custom fields are defined in the content model, when we publish or edit real estate articles, we can see and fill in these new field contents in the "Other Parameters".This data is the basis for our subsequent filtering.

Display filtering results: FlexiblearchiveListTag

In the frontend template,archiveListThe tag is the core of AnQi CMS for fetching and displaying article lists.It can list articles based on conventional parameters such as category ID, model ID, and more, and can also dynamically receive custom parameters through URL query parameters (Query Parameter) to display filtered results.

For example, if we want to display a list of properties where the house type is "apartment" and the number of bedrooms is "3", the URL may become something likehttp://你的网站地址/properties/list?house_type=apartment&bedrooms=3in the form of.archiveListLabels will automatically identify and process these URL parameters, and then only return article data that meets the conditions.

We can use it like this in the template.archiveListPrepare a list of articles that supports pagination and filtering:

{% archiveList archives with moduleId="你的房产模型ID" type="page" limit="10" %}
    {% for item in archives %}
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>房屋类型:{{item.house_type}}</p>
            <p>卧室数量:{{item.bedrooms}}</p>
        </a>
    {% empty %}
        <p>抱歉,没有找到符合条件的房源。</p>
    {% endfor %}
{% endarchiveList %}

here,moduleIdSpecified the content model we want to query,type="page"then it means this is a paginated list,limit="10"setting the number of articles displayed per page.item.house_typeanditem.bedroomsIt is the custom field defined through the content model that can be displayed directly in the list item.

Build a filter interface: intelligent.archiveFiltersTag

It is not convenient to manually filter through URL parameters, we need a user-friendly filtering interface. Anqi CMS provides this for us.archiveFiltersThe tag can automatically generate a series of filter options that users can select based on the custom fields defined in our content model.

archiveFiltersTags are usually witharchiveListWhen used together, it intelligently identifies which custom fields in the current model are set to be available for filtering, and then generates a corresponding list of filter options for these fields, including the display name of each option, the corresponding filter link, and the current selection status.

Here is a rough template structure for building a filter interface:

<div>
    <h3>筛选房源</h3>
    {% archiveFilters filters with moduleId="你的房产模型ID" allText="不限" %}
        {% for item in filters %}
            <div class="filter-group">
                <span>{{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>

In this example,archiveFiltersA tag defined a namedfiltersvariable is used to store all the filter condition data.moduleIdparameter ensures that it only generates filters for specified content models.allText="不限"Each filter group provides an 'unlimited' option for users to clear a specific filter condition.

Through the outer layerfor item in filtersLoop, we can traverse all the filterable custom fields (such as "house type", "number of bedrooms"). Next, the innerfor val in item.ItemsThe loop will list all the optional values under this field (such as 'apartment', 'villa', etc.).val.LinkIt will automatically generate a URL with the correct query parameters, andval.IsCurrentIt will help us add styles to the currently selected filter conditions (for example, highlighting).

Enhance user experience: seamless integration of filtering and pagination.

While implementing the filtering function, pagination is also an indispensable part. Anqi CMS'sarchiveListThe tag is intype="page"mode, will bepaginationtags work perfectly together. After the user applies the filtering conditions,paginationThe page number link generated by the tag will automatically include the current filter parameters.This means that whether it is page turning or switching filter conditions, the parameters in the URL will be intelligently passed and updated to ensure that the user can always see the correct filtering results and have a smooth browsing experience.

The AnQi CMS through the flexible definition of content models,archiveListthe intelligent parsing of URL parameters, as well asarchiveFiltersAutomated generation of the filter interface provides us with a set of efficient and easy-to-use article list filtering solutions.This allows us to create a rich, responsive and personalized content browsing experience for users without delving into complex coding.


Frequently Asked Questions (FAQ)

1. The parameters I customized in the content model can be directly used inarchiveListAre they displayed in the list?Of course, as long as you define custom fields (such ashouse_type), inarchiveListthe loop, you can directly access{{item.house_type}}This form is used to call and display the value of the field. Anqi CMS will pass these custom fields as part of the article data to the template.

How to set a default value for custom filter option or display an 'All/Unlimited' option?While usingarchiveFiltersBy setting theallTextparameter to achieve this. For example,{% archiveFilters filters with moduleId="1" allText="不限" %}It will generate an option named 'Unlimited' at the first position in each filter group, whose link will usually clear the URL parameters of the filter field, thus displaying all results.

3. How does AnQi CMS handle URLs when filtering based on multiple custom parameters?The Anqi CMS automatically combines multiple filter parameters into the URL query string. For example, when the user selects 'Apartment' as the 'House Type' and '3' as the 'Number of Bedrooms',archiveFiltersThe link will be generated?house_type=apartment&bedrooms=3.archiveListTags can intelligently parse and process all valid query parameters in the URL to ensure the accuracy of the filtered results.

Related articles

How to use a filter in AnQiCMS template to convert a timestamp to a readable date format?

In website operation, we often need to display various time information on the front-end page, such as the publication date of articles, content update time, or user comment time.AnQiCMS as an enterprise-level content management system usually adopts the efficient and concise format of Unix timestamps for data storage.However, for users visiting the website, a string of numeric timestamps is obviously not intuitive and friendly.How can I convert these timestamps into a readable date format in AnQiCMS templates?AnQiCMS provides a very practical built-in tag and filter

2025-11-08

How does AnQiCMS automatically extract the first image of the article content as a thumbnail?

In content operation, matching a suitable thumbnail for each article can not only enhance the visual appeal of the website, but also quickly attract users' attention in the information stream.However, manually uploading and adjusting thumbnails for each article, especially when the volume of content is large, is undoubtedly a time-consuming and labor-intensive task.AnQi CMS knows this pain point and provides an intelligent and efficient thumbnail automatic extraction mechanism, making content publishing more hassle-free.

2025-11-08

How to retrieve and display custom parameters of an article on the article detail page (such as author, source)?

Manage and display content in Anqi CMS, the article detail page is undoubtedly the core position for users to obtain information.In addition to basic elements such as article titles and text, we often need to display some personalized information on the detail page, such as the author of the article, source of content, product specifications, and release location, etc.This information is called "Custom Parameters" in Anqi CMS, which can greatly enrich the dimensions of content and meet the personalized needs of different business scenarios.The AnQi CMS provides a very flexible way to define and display these custom parameters, allowing website operators to meet their actual needs

2025-11-08

How does AnQiCMS manage image resources and display them by category for easy front-end calling?

In website content operation, images are indispensable elements to attract users and convey information.Efficiently manage these image resources and be able to call them flexibly on the front-end page, which is crucial for improving the user experience and operational efficiency of the website.AnQiCMS provides a comprehensive and flexible solution in this regard, making the management and invocation of image resources simple and orderly. ### Centralized Management and Categorization of Image Resources AnQiCMS provides a centralized management platform for website image resources, where you can easily upload, store, and organize all visual content.In the background management interface

2025-11-08

How to safely parse a URL string into a clickable a tag in AnQiCMS template?

In website content operation, we often need to display some website URLs, email addresses, and other information in articles, introductions, or custom fields.If this information is just plain text, users cannot click to jump directly, which not only affects the user experience but may also reduce the interactivity of the content and the SEO friendliness of the website.Convert these URL strings securely and intelligently into clickable `<a>` tags, which is a very practical feature in the AnQiCMS template.AnQiCMS as an enterprise-level content management system has fully considered the flexibility and security of content display from the beginning of its design

2025-11-08

How to enable anti-crawling interference code and image watermark in AnQiCMS to protect the display of content?

In today's era of increasingly rich digital content, protecting original content on websites is particularly important.AnQiCMS (AnQiCMS) understands the pain points of content creators and corporate users, and has specifically built anti-crawling interference codes and image watermarking functions to help users effectively prevent their content from being maliciously scraped and stolen, while also strengthening brand identity.### Protect content security: Enable anti-capture interference code The value of original content is self-evident, but information collection tools on the Internet may copy your articles in large quantities without permission, which not only harms the rights and interests of the original creators but may also divert website traffic

2025-11-08

How to implement pagination display and like function for comment content in AnQiCMS?

In website operation, user comments and interaction are the key to enhancing the vitality of content.AnQiCMS (AnQiCMS) provides powerful content management capabilities, among which the comment feature is an important bridge for user interaction with content.This article will discuss in detail how to implement pagination for comment lists in Anqi CMS, as well as add a like function for comment content, enhancing the interactive experience of your website to a higher level.### CMS Review Function Overview The CMS has built-in article comment and comment management functions from the early version, which provides native user interaction support for the website

2025-11-08

How to debug variable content and type in AnQiCMS template (using dump filter)?

When using AnQiCMS to build websites and customize templates, we often encounter situations where the content displayed on the page is not as expected, or it seems that a variable is not passing correctly.At this moment, it is particularly important to be able to quickly view the actual content and data type of variables in the template.Fortunately, AnQiCMS's template engine (which adopts a syntax similar to Django) provides us with a very practical tool—the `dump` filter, which helps us easily reveal the mysteries of variables.### Core Function: `dump`

2025-11-08