How to filter tags through document parameters to achieve a combination display of list content with multiple conditions?

Calendar 👁️ 71

In content operations, we often need to display lists of content with different themes and properties, and allow visitors to filter according to their own needs. For example, a real estate website may need to filter properties according to "property type", "location", "area range", and other multi-dimensional combinations.If each time is organized manually or developed custom, it is not only inefficient but also difficult to maintain.AnQiCMS provides a flexible and powerful document parameter filtering mechanism that can help us easily achieve this combination display of list content with multiple conditions.

Next, we will delve into how to use the document parameter filtering tags of Anqi CMS to build dynamic content lists that meet user needs and are easy to manage.

The cornerstone of building a flexible filtering system: Custom content model

The first step to implementing multi-condition filtering in Anqi CMS is to define clear, filterable properties for our content.This is due to its powerful 'flexible content model' feature.We can create or modify content models based on business requirements (such as "article model", "product model", and even custom "property model", "commodity model" etc.), and add various "custom fields" to them.

These custom fields are the source of our multi-condition filtering implementation.When adding fields, you can choose different field types, such as single-line text, numbers, multi-line text, single selection, multiple selection, and dropdown selection. Among them,Single choice, multiple choice, and dropdown choiceThese three types are particularly suitable for use as filtering conditions. For example, in the 'property model', we can add:

  • House type(Dropdown selection: Residential, Shop, Apartment)
  • Room type(Single selection: One room, Two rooms, Three rooms)
  • Decorating situation(Multiple selection: Finishing, Simplified finishing, Raw finishing)
  • Area(Single line text, but can be configured as a filter condition in the background)

When defining these fields, we also need to provide default values for fields of type selection, radio, and checkbox, which will serve as selectable items on the frontend filtering interface.

Content release: Provide data for filtering

After custom content models and field definitions are completed, we need to fill in the contents of these custom fields specifically when publishing or editing documents.Only when the document contains this parameter information, can they be correctly retrieved and displayed in the front-end filter list.For example, when publishing a real estate information, we will choose its 'house type', 'layout', and 'decoration', and fill in the 'region'.

Design the front-end filtering interface:archiveFiltersThe clever use of tags

Now, we have filterable content and well-defined filtering dimensions. Next, it's about how to display these filtering conditions on the website front-end. Anqi CMS providesarchiveFiltersLabel, used specifically to generate these filters.

This tag will intelligently read the custom fields you define in the content model and dynamically generate filter links based on the current page URL.We can place it anywhere we need to display a filter, such as the sidebar or top of the list page.

This is a typicalarchiveFiltersLabel and its usage examples:

{# 参数筛选代码 #}
<div class="filter-section">
    <div class="filter-title">参数筛选:</div>
    {% archiveFilters filters with moduleId="1" allText="全部" %}
        {% for item in filters %}
        <ul class="filter-group">
            <li class="group-label">{{item.Name}}: </li> {# 显示参数名称,如“房屋类型” #}
            {% for val in item.Items %}
            <li class="filter-option {% if val.IsCurrent %}active{% endif %}">
                <a href="{{val.Link}}">{{val.Label}}</a> {# 生成筛选链接,并高亮当前选中项 #}
            </li>
            {% endfor %}
        </ul>
        {% endfor %}
    {% endarchiveFilters %}
</div>

In this code snippet:

  • filtersIt is a custom variable name used to receivearchiveFiltersThe data returned by the label.
  • moduleId="1"Specify the content model (for example, 'article model') we want to filter by ID 1.If we need to filter "Product Model" or "Real Estate Model", we need to replace it with the corresponding model ID.
  • allText="全部"Set the display text for the “All” option in each filter group, if you do not want to display it, you can set it toallText=false.
  • {% for item in filters %}Loop through all available filter parameters,item.NameThe parameter name will be displayed (such as "House type"),item.FieldNameIt is the corresponding field name.
  • {% for val in item.Items %}Next, we traverse the optional values under each parameter,val.LabelIt is the display text of the option (such as "Residential"), whileval.Linkit is automatically generated by the Anqi CMS, containing the current filtering conditions URL.
  • {% if val.IsCurrent %}active{% endif %}This line of code is very useful, it will automatically judge whether the current option is selected, thus facilitating us to add CSS styles to the selected items to enhance the user experience.

By this means,archiveFiltersThe tag not only helps us build the filter UI, but more importantly, itautomatically handles the filtering logicputs the selected parameters as a query string in the URL (for example?house_type=住宅&area=市中心Attach to the link.

Dynamic display of content list:archiveListIntelligent response of tags

We need a list that can dynamically display content based on these filtering conditions, as we have a filtering interface. Anqi CMS'sarchiveListThe tag shows its intelligence here.

archiveListThe tag is intype="page"In the mode, it can not only achieve pagination function, but alsoautomatically parse the query parameters in the current URLThis will filter the document content with these parameters. This means that we do not need to manually retrieve the URL parameters and pass them toarchiveListEverything is automatically done!

The following is an example used in conjunction with the above filterarchiveListLabel example:

`twig {# Document list code #}

{% archiveList archives with moduleId=“1” type=“page” limit=“10” %}

{% for item in archives %}
<div class="list-item">
    <a href="{{item.Link}}">
        <h5 class="item-title">{{item.Title}}</h5>
        <p class="item-description">{{item.Description}}</p>
        <div class="item-meta">
            <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            <span>阅读量:{{item.Views}}</span>
        </div>
    </a>
    {% if item.Thumb %}
    <a href="{{item.Link}}" class="item-thumb">
        <img alt="{{item.Title}}" src="{{item.Thumb}}">
    </a>
    {% endif %}
</div>
{% empty %}
<p class="no-content">该列表没有任何内容</p>
{% endfor %}

{% endarchiveList %}

{# 分页代码 #}
<div class="pagination-section">
    {% pagination pages with show="5" %}
        <a class="pagination-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>
        {% if pages.PrevPage %}
        <a class="pagination-link" href="{{pages.PrevPage.Link}}">上一页</a>
        {% endif %}
        {% for item in pages.Pages %}
        <a class="pagination-link {% if item.IsCurrent %}active{% endif %

Related articles

How to display associated categories and tags lists on the article detail page?

When managing website content in AnQi CMS, the article detail page is the core page for users to obtain information.In addition to the content of the article itself, displaying the category information and related tag list of the article to the visitor can greatly improve the user experience, help visitors quickly understand the context of the article, and effectively enhance the internal link structure of the website, which is greatly beneficial for search engine optimization (SEO).Next, we will discuss how to flexibly display these related information on the article detail page of Anqi CMS.AnQi CMS uses an intuitive and powerful template tag system

2025-11-08

How to format the timestamp of an article into a readable date and time format for display?

In website content operation, the time of article publication or update is an important element in conveying information to visitors.A clear and readable date and time format not only improves user experience but also allows visitors to quickly understand the timeliness of the content.AnQi CMS provides a very practical template tag to help us easily achieve this goal.### Core Tool: `stampToDate` Tag Anqi CMS allows us to use the `stampToDate` tag

2025-11-08

How to call the cover main image, thumbnail, and group image to enrich the display effect?

In website operation, images are indispensable elements to attract visitors and convey information.Reasonably using the cover image, thumbnail, and group image of the article can greatly enhance the visual appeal of the website, enrich the form of content presentation, and make your content more vivid and attractive.AnQiCMS as a flexible and efficient content management system provides an intuitive way to manage and call these image resources, helping you easily achieve diverse image display effects.Understanding the image types in AnQiCMS

2025-11-08

How to truncate overly long content on the article detail page and add an ellipsis?

In website operation, we often encounter such situations: an article is rich in content, but when it is displayed on the list page, the recommendation area, or some abstract module on the article detail page, we only want to display a part of the content and end it with an ellipsis to maintain the neatness of the page and the fluency of reading.If the entire content is displayed directly, the page will appear lengthy, affecting user experience.Luckyly, AnQiCMS provides us with a very flexible and powerful template mechanism, allowing us to easily truncate long content and elegantly add ellipses to enhance the overall page effect

2025-11-08

How to implement pagination for article lists and limit the number of items per page?

In website operation, especially when managing a large amount of content, the pagination display of the article list is an indispensable function.It not only makes it easier for users to browse content, avoids the problem of too much data loading on a single page leading to slow speed, but also improves the overall user experience and SEO friendliness of the website.In AnQi CMS, it is very intuitive to implement pagination for the article list and flexibly control the number of items per page. Next, we will explore how to implement pagination for the article list in the Anqi CMS template and limit the number of articles displayed per page.--- ### Efficient Content Management

2025-11-08

How to display related documents or search results on the article list page?

In website operation, how to make visitors find the content they are interested in faster, or seamlessly discover more related information after browsing an article, is the key to improving user experience and website stickiness.AnQiCMS (AnQiCMS) provides powerful and flexible template tags that can help us easily implement displaying related documents or search results on the article list page, thus building a more intelligent and interactive website.### Smartly using content list tags to present dynamic information One of the core advantages of AnQi CMS lies in its highly customizable template system

2025-11-08

How to get and display the custom parameters of a specified document (such as author, source)?

When using AnQi CMS to manage your website content, you may find that relying solely on default fields such as title, content, and summary is not enough to fully meet the needs of personalized display.For example, you may wish to display 'author' and 'source' information on the article detail page, or show 'material' and 'size' and other specific parameters on the product page.The AnQi CMS provides powerful custom parameter features, allowing you to easily add, manage, and display these personalized information for different types of documents (such as articles, products).This article will provide a detailed introduction on how to obtain and display custom parameters of specified documents in AnQi CMS

2025-11-08

How to get and display the list of all documents associated with a specified Tag?

Manage content in AnQi CMS, besides organizing through categories, flexibly using the "Tag" feature is also the key to improving the aggregation ability of website content and user experience.Tags can connect documents of different categories, different models, but with the same theme, providing visitors with more ways to discover content.How can we specifically retrieve and display the list of all documents associated with the specified tags?Next, we will delve deeper into this practical skill. ### Understanding the Tag System of AnQi CMS The tag design of AnQi CMS is very flexible, it does not depend on any specific category or model

2025-11-08