How to display filter conditions on the document list page of Anqi CMS and dynamically update results based on parameters?

Calendar 👁️ 60

In AnQi CMS, adding filtering conditions to the document list page and dynamically updating the results based on user selection is an important factor in improving the discoverability and user experience of website content.This not only helps visitors quickly locate the content they are interested in, but also has a positive impact on SEO through a clear URL structure.Let's understand step by step how to implement this feature in Anqi CMS.

Core Function: Content Model and Custom Fields are Basic

In AnQi CMS, all content is built based on the 'Content Model'.The filtering function on the document list page is based on the various custom fields you define in the content model.Therefore, before implementing the front-end filtering, we need to ensure that the content model you have already included contains the custom fields that need to be filtered, and that the values of these fields have been filled in the content of your documents.

For example, if you want to create a real estate website, you may need to filter according to the 'property type' (such as apartment, villa, shop) or 'area range' (such as 50-70 square meters, 70-90 square meters).These 'house types' and 'area ranges' need to be added in the background 'Content Management' -> 'Content Model' for your 'real estate model'.

When defining custom fields, AnQiCMS usually provides an option for you to decide whether the field should be applied to frontend filtering.For single-choice, multiple-choice, or dropdown field types, AnQiCMS automatically identifies the option values as conditions available for front-end filtering.When these fields are set as filterable, AnQiCMS can automatically generate the conditions and logic required for front-end filtering according to these definitions.

Step 1: Display Filter Conditions in the Template

With the customizable filter fields, the next step is to display these filter conditions in the document list page template. Anqi CMS provides a very convenient template tag ——archiveFilters.

archiveFiltersThe tag can automatically extract all selectable custom fields and their corresponding option values according to the specified content model, and generate HTML code with filter links.This greatly simplifies front-end development work.

Let's take a look at its basic usage:

{# 参数筛选代码,通常放在列表页顶部或侧边栏 #}
<div>
    <h3>筛选条件:</h3>
    {% archiveFilters filters with moduleId="1" 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>

In this example:

  • filtersIs a variable name we define to receivearchiveFiltersThe data set returned by the tag.
  • moduleId="1"Specify the filter parameters for the content model we want to retrieve with ID 1 (for example, an article model). You can replace it with your actual content model ID according to your needs.
  • allText="不限"Defined as the display text for the "All" or "Unlimited" option. If you do not want to display it, you can set it toallText=false.
  • {% for item in filters %}Loop through each filterable custom field (such as "House Type", "Area Range").
    • item.NameIt will display the Chinese name of the field (such as "House Type").
    • {% for val in item.Items %}Continue to loop through all the optional values of the current field (such as 'apartment', 'villa').
      • val.LabelIt will display the text of the option (such as 'apartment').
      • val.LinkIt is the most critical part, it generates a URL containing the current filter parameters. When the user clicks on this link, the page URL will be updated and will include the corresponding query parameters.
      • val.IsCurrentIt is a boolean value indicating whether the current option is selected. We can use it to add selected filtering conditions.activeClass name, so that it can be highlighted by CSS to enhance the user experience.

Step two: Make the document list responsive to filtering

When the user clicks onarchiveFiltersAfter generating the filter link, the page URL will dynamically add the corresponding query parameters (such as?房屋类型=公寓)。At this time, we need to ensure that the document list can recognize and update the display results according to these parameters.

Of Security CMSarchiveListThe label performs very intelligently and conveniently in this aspect. When it is used to generate pagination lists (type="page"), it willautomatically read the query parameters from the current URLAnd apply it as a filter condition to the document query.

The following is an example of code for a document list with a filter function.

`twig {# Document list code #}

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

{% for item in archives %}
<div class="document-item">
    <a href="{{item.Link}}">
        <h4 class="document-title">{{item.Title}}</h4>
        <p class="document-description">{{item.Description|truncatechars:100}}</p>
        <div class="document-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="document-thumb">
        <img alt="{{item.Title}}" src="{{item.Thumb}}">
    </a>
    {% endif %}
</div>
{% empty %}
<p>抱歉,没有找到符合条件的文档。</p>
{% endfor %}

{% endarchiveList %}

{# 分页代码,与archiveList的type="page"配合使用 #}
<div class="pagination-wrapper">
    {% pagination pages with show="5" %}
        {# 首页 #}
        <a class="pagination-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {# 上一页 #}
        {% if pages.PrevPage %}
        <a class="pagination-link" href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        {% endif %}
        {# 中间多页 #}
        {% for item in pages.Pages %}
        <a class="pagination-link {% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
        {% endfor %}
        {# 下一页 #}
        {% if pages.NextPage %}
        <a class="pagination-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        {% endif %}
        {# 尾页 #}
        <a class="pagination-link {%

Related articles

How to display dynamic breadcrumb navigation and customize its display in Anqi CMS?

When we browse websites, we often see a line at the top or bottom of the page indicating the current navigation path, which is what we usually call 'Breadcrumbs'.It can not only clearly tell the user the position of the current page in the website structure, but also effectively improve the user experience and search engine optimization (SEO) effect of the website.AnQiCMS (AnQiCMS) is a powerful content management system that comes with a convenient way to generate and customize this dynamic breadcrumb navigation.

2025-11-09

How to implement flexible navigation menu and submenu display in AnQi CMS template?

In website operation, a clear and intuitive navigation menu is the core of user experience.It can not only help visitors quickly find the information they need, but it is also a direct embodiment of the structure and content organization logic of the website.AnQiCMS (AnQiCMS) leverages its efficient architecture based on the Go language and Django-style template engine to provide great flexibility for content creators and developers, enabling the display of various complex navigation menus and sub-menus.Implement flexible navigation menus and sub-menus in the AnQi CMS template

2025-11-09

How to set the SEO display rules for article, product, page titles and other content in AnQi CMS?

In website operation, the content title is like the facade of the website, it is not only the first impression seen by visitors, but also an important basis for search engines to understand the content of the page and judge its relevance.A meticulously optimized content title that can significantly improve the click-through rate (CTR) and ranking of the website.AnQiCMS (AnQiCMS) as a highly SEO-friendly content management system, has provided us with very flexible and powerful tools to finely set the SEO display rules for articles, products, pages, and other content. Next

2025-11-09

How does the custom content model of AnQi CMS affect the display of front-end data fields?

In website content management, flexibility is the key to improving efficiency and user experience.AnQiCMS (AnQiCMS) performs well in this aspect, with its custom content model feature being particularly powerful.It not only makes content management more organized, but also directly affects the way website front-end data is displayed, making it easy for the website to adapt to various content structures and business needs. ### Understanding Custom Content Model One of the core strengths of Anqi CMS lies in its "flexible content model".

2025-11-09

How to display the links and titles of the previous and next documents in AnQi CMS?

How to easily display the link and title of the previous and next document in AnQi CMS?When browsing website articles, we often hope to smoothly jump from the current content to the previous or next related article. This seamless reading experience not only enhances user satisfaction but also has a positive effect on the overall structure of the website's content and SEO optimization.AnQi CMS is well-versed in this, providing content operators with an extremely convenient way to deploy such navigation functions with its flexible and powerful template engine.

2025-11-09

How to display related recommended documents on the document detail page of AnQi CMS and customize the recommendation logic?

After visitors have read an interesting document or viewed a product introduction on your website, if they can get more relevant recommendations in a timely manner, it will undoubtedly greatly enhance their visit experience, extend their stay time, and encourage them to explore more corners of the website.AnQi CMS knows this and provides flexible and diverse features to help you cleverly display related recommendations on the document detail page, and can customize the recommendation logic according to your operational strategy. We will delve into how to implement this feature in Anqi CMS in detail.###

2025-11-09

How to use Anqi CMS tags and filters to format date and timestamp display?

The timeliness and readability of website content largely depend on the accuracy and aesthetics of date and time information.AnQi CMS as an efficient content management system provides flexible tags and filters, helping us easily implement personalized display of dates and timestamps, making your website content more in line with user habits and enhancing the overall reading experience.This article will deeply explore how to巧妙运用these functions in Anqi CMS, converting raw time data into a clear and understandable display form.### Understand the Date and Time Data in Anqi CMS In Anqi CMS

2025-11-09

How to display the friend link list in Anqi CMS and distinguish the rel="nofollow" attribute?

Friendship links play an important role in website operation, they not only help to increase the number of external links on the website, but also have a positive impact on search engine optimization (SEO), and can also provide users with more related resource entries.However, not all friendship links are suitable for passing weight or obtaining search engines' 'recommendations', at this point the `rel="nofollow"` attribute is particularly important.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers the needs of website operators and provides a convenient link management function

2025-11-09