How to filter and display a specific list of documents based on keywords in AnQi CMS?

Calendar 👁️ 71

When using AnQi CMS to manage website content, we often need to search and display related document lists based on specific keywords.It is crucial to master the method of keyword filtering, whether it is to create an in-site search results page or to display content closely related to a theme on a specific topic page.AnQi CMS provides flexible and powerful template tag functions, making this task intuitive and efficient.

Basics of keyword filtering:archiveListlabel'sqParameter

AnQi CMS through its corearchiveListThe tag is used to handle the retrieval of document lists. This tag not only allows filtering based on common conditions such as categories and models, but also provides a very practicalqThe parameter is specifically used for title search based on keywords.

When you need to display documents on the website front-end based on the user's input keywords,qThe parameter comes into play. For example, if the user enters "Anqi CMS tutorial" in the search box, we can pass this keyword toarchiveListThe tag will automatically match all documents containing "AnQi CMS tutorial" and list them.

A basic application scenario is on the search results page. The backend receives the keyword submitted by the user through the search form, and then uses it asqThe value of the parameter, called in the templatearchiveListTags:

<form method="get" action="/search">
    <div>
        <input type="text" name="q" placeholder="请输入搜索关键词" value="{{urlParams.q}}">
        <button type="submit">搜索</button>
    </div>
</form>

{% archiveList archives with type="page" q=urlParams.q limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
            <div>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</div>
        </a>
    </li>
    {% empty %}
    <li>
        抱歉,没有找到符合“{{urlParams.q}}”关键词的文档。
    </li>
    {% endfor %}
{% endarchiveList %}

{% pagination pages with show="5" %}
    <!-- 分页导航代码 -->
{% endpagination %}

In the above example,urlParams.qWill dynamically obtain the query parameter value namedqand then pass it as a keyword toarchiveList.type="page"The parameter indicates that we want to paginate the results, combiningpaginationTags can facilitate the generation of pagination navigation.

Using the content model to customize fields for advanced filtering

In addition to keyword filtering of document titles, the strong point of Anqi CMS is that it supports custom content models.This means we can add dedicated custom fields for different content types (such as articles, products, cases, etc.).These custom fields can not only enrich the content details but also serve as filtering conditions to achieve more accurate keyword filtering.

These custom fields defined in the document's "Other Parameters", such as "House Type", "Area", "Price Range", etc., can all be used as filter conditions on the front end. The key to achieving this advanced filtering is:

  1. Define filterable fields in the background content modelIn the content model settings, check the 'Filterable' option for fields that need to be filtered.
  2. Pass the filter value through the URL query parametersIn the front end, we can add custom field names and values in the form of URL query parameters (for example?房屋类型=住宅&地区=上海) to the URL of the document list page.
  3. UsearchiveFiltersLabel generation filter options: To facilitate user selection of filtering conditions, you can usearchiveFiltersTags dynamically generate these custom field filter options on the page.This label will automatically generate a filter list with correct links and selected states based on the content model you define and the current URL filtering status.

For example, if we have a real estate model and define custom fields such as 'House Type' and 'Area', we can organize it on the list page:

<div>
    <h3>房源筛选</h3>
    {% archiveFilters filters with moduleId="1" allText="不限" %}
        {% for item in filters %}
        <ul>
            <li>{{item.Name}}: </li> {# 例如:房屋类型 #}
            {% for val in item.Items %}
            <li class="{% if val.IsCurrent %}active{% endif %}">
                <a href="{{val.Link}}">{{val.Label}}</a>
            </li>
            {% endfor %}
        </ul>
        {% endfor %}
    {% endarchiveFilters %}
</div>

{# 文档列表会根据URL中的筛选参数自动调整 #}
{% archiveList archives with type="page" moduleId="1" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
        </a>
    </li>
    {% endfor %}
    {% empty %}
    <li>
        没有找到符合条件的房源。
    </li>
{% endarchiveList %}

{% pagination pages with show="5" %}
    <!-- 分页导航 -->
{% endpagination %}

In this example,archiveFiltersTags will generate filters such as "House Type", "Area", etc., each option will generate a link, clicking on which will update the URL parameters and reload the document list,archiveListThe tag will display the matching documents based on all the filter parameters passed in the URL (including keywordsqand custom fields).

Key points of template integration and display

Please note the following points when integrating these filtering features into your website template:

  • ConsistencyEnsure that thenameproperties such asname="q") andarchiveListin the labelqparameters correspond.
  • User ExperienceAfter the user filters or searches, keep the filtering conditions visible on the page and clearly indicate the current selected filtering status, which can significantly improve the user experience.archiveFilterslabel'sIsCurrentProperty provides good support in this aspect.
  • Page processing: The document list after filtering usually also needs to be displayed in pages, so don't forget to matchpagination.
  • Empty result prompt: Use.forrepeatedlyemptyBlock handles the case of not finding a matching document gracefully, giving the user a friendly prompt.

By the above method, AnQi CMS makes it very flexible and powerful to filter and display specific document lists based on keywords, whether it is simple on-site search or complex faceted navigation (multidimensional filtering), it can be easily realized.


Frequently Asked Questions (FAQ)

1. I want to create a dedicated search page where users can enter keywords and see the results. How should I implement it?You can create a page namedsearch/index.htmlTo implement a template file. In this template, place a search form,actionproperty points to/search,inputfield'snameset the attribute toq. Then, usearchiveListLabel, andqThe parameter value is set tourlParams.qto get the document list corresponding to the user's input keywords. At the same time, combinepaginationTags can enable pagination of search results.

2. Besides keyword search, can I also filter by 'region' and 'house type' of the document?Of course. Anqi CMS'sarchiveListThe tag supports receiving multiple URL query parameters for filtering. If you have defined custom fields such as 'region' and 'house type' in your content model and these fields are marked as filterable, then you just need to include these parameters in the URL, for example/search?q=公寓&地区=上海&房屋类型=住宅.archiveListThe document will be filtered based on all matching conditions. You can also usearchiveFilterstags to generate these multi-dimensional filtering options on the front end.

3. What will the page display if no documents are found after searching or filtering?InarchiveListwithin the tag,forIn the loop, you can add a{% empty %}block. When no documents match the filtering criteria, forThe loop will executeemptyContent within the block, rather than iterating through the document. This way, you can place a friendly prompt here, such as 'Sorry, no documents matching the criteria were found.'

Related articles

How to use the global settings of Anqi CMS to unify the display of copyright information and contact details on the website?

In website operation, copyright statements and contact information are important components for building brand trust, providing user support, and ensuring legal compliance.AnQiCMS (AnQiCMS) fully understands the importance of this information, and therefore provides an intuitive and powerful global setting function, allowing website administrators to uniformly and conveniently control the display of these contents without frequent code modifications.Imagine if your website has hundreds of pages and you need to manually edit each page every time you update the copyright year or customer service phone number, it would be such a繁琐 and error-prone task.

2025-11-09

How to implement pagination functionality in Anqi CMS and customize the display style of page numbers?

In AnQi CMS, the pagination feature of website content is an indispensable part of improving user experience and optimizing site structure.Whether it is a list of blog articles, product display pages, or other dynamic content, reasonable pagination makes it easier for users to browse a large amount of information and also helps search engines better understand and extract website content.Today, let's delve deeper into how to implement pagination in AnQiCMS and customize the display style of page numbers according to your own needs. ### Why do we need pagination? Imagine that your website has hundreds or even thousands of wonderful articles.If there is no pagination

2025-11-09

How to correctly render Markdown content as HTML and display mathematical formulas or flowcharts in Anqi CMS?

In AnQi CMS, using Markdown format to write content not only improves editing efficiency, but also maintains the structuralization and readability of the content.When content involves complex mathematical formulas or a clear flowchart needs to be displayed, the strength of Markdown becomes evident.Our company provides good support for this, let's take a look at how to correctly render and display these advanced contents on the website.### Step 1: Enable Markdown Editor First, make sure that your CMS system has enabled the Markdown editor feature

2025-11-09

How does AnQi CMS truncate long text content and add an ellipsis?

In website content operation, effectively displaying information while maintaining the page's cleanliness and the smoothness of user experience is a crucial link.Especially for long text content, how to truncate the display on the list page or overview section with an ellipsis is a common technique to improve the readability and aesthetics of the website.AnQiCMS (AnQiCMS) is a feature-rich management system that provides a flexible mechanism to meet this requirement at the template layer.

2025-11-09

How to display the document category list at different levels in Anqi CMS and its associated documents?

How to efficiently organize and display a large amount of content in website operation is the key to improving user experience and website usability.For those who use AnQiCMS, the system provides powerful content model and template tag features, which can help us easily implement multi-level document classification lists and clearly display the associated documents under each category. Let's explore together how to build a website navigation with both hierarchy and rich content using these features in Anqi CMS.### Understand the content structure of AnQi CMS In AnQi CMS

2025-11-09

How to customize the Title and Description of Anqi CMS website to optimize search engine results display?

In today's highly competitive online environment, whether a website can stand out in search engines largely depends on its optimization of details.Among them, the page's Title (title) and Description (description) play a crucial role, as they are the 'business card' of the website presented on the search engine results page (SERP).Carefully customize these elements, which can not only help search engines better understand the page content, but also attract potential visitors to click, thereby improving the traffic and visibility of the website.AnQiCMS (AnQiCMS) as a powerful content management system

2025-11-09

How to implement independent management and unified display of multi-site content on the front end for AnQi CMS?

In today's digital age, many businesses and content operators face a common challenge: how to efficiently manage multiple brand websites, product sub-sites, or content platforms, ensuring that each site runs independently while also achieving flexible integration of content and resources?AnQi CMS is born to solve this pain point, it provides a set of elegant and practical solutions, making independent management and unified display of multi-site content accessible.One of the core strengths of AnQi CMS is its powerful multi-site management capability.When you need to operate multiple websites, such as a corporate website

2025-11-09

How to use the flexible content model of AnQi CMS to display different types of content structures (such as articles, products, events)?

The Anqi CMS provides a powerful core capability in content management, that is, its highly flexible content model.This feature allows us to freely define and organize various types of content according to the actual needs of the website, whether it is traditional articles and information, detailed product introductions, or time-sensitive event publications, all of which can be managed efficiently and orderly within the same system.It breaks free from the constraints of traditional CMS fixed content types, allowing us to focus more on the business logic itself rather than being restricted by the system framework

2025-11-09