When using the 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 keyword filtering method, whether for creating an in-site search results page or displaying content closely related to a specific topic on a special page.AnQi CMS provides flexible and powerful template tag functions, making this task intuitive and efficient.
Basic of keyword filtering:archiveListTagsqParameters
AnQi CMS through its corearchiveListThis tag can be used to process the retrieval of document lists. This tag not only allows filtering based on conventional conditions such as categories, models, etc., but also provides a very practicalqParameters, specifically used for keyword-based title search.
When you need to display documents on the website front-end based on the user's input keywords,qParameters come into play. For example, if the user enters 'AnQi CMS tutorial' in the search box, we can pass this keyword toarchiveListLabel, it will automatically match all documents containing "AnQi CMS tutorial" from the document title and list them.
An essential application scenario is on the search results page. After the user submits the keywords through the search form, the backend will receive this keyword and then use 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 namedqfrom the URL, and then pass it as a keyword toarchiveList.type="page"The parameter indicates that we want to handle the results with pagination, combined withpaginationTags can facilitate the generation of pagination navigation.
Use the content model to customize fields for advanced filtering
In addition to keyword filtering of document titles, the powerful aspect 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 criteria, achieving more accurate keyword filtering.
These custom fields defined in the 'Other Parameters' section of the document, such as 'House Type', 'Area', 'Price Range', etc., can all be used as filtering criteria on the front end. The key to implementing this advanced filtering is:
- Define filterable fields in the background content modelIn the content model settings, check the 'Filterable' option for fields that need to be filtered.
- Pass the filter values through URL query parametersIn the frontend, 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. - Use
archiveFiltersTag generation filter optionsTo facilitate user selection of filtering conditions, you can usearchiveFiltersTags dynamically generate these custom field filter options on the page.This tag will automatically generate a filter list with correct links and selected states based on the content model you define and the current URL filter status.
For example, if we have a property model and define custom fields such as 'House Type' and 'Area', we can organize the list page like this:
<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 'House Type', 'Area' and other filtering conditions, each option will generate a link, clicking on which will update the URL parameters and reload the document list.archiveListTags will be displayed based on all the filtering parameters passed in the URL (including keywords) 【en】qand custom fields) to show matching documents. 【en】
Key points of template integration and display 【en】
When integrating these filtering features into your website template, please note the following points:
- ConsistencyMake sure the search form's
nameproperty (such asname="q") corresponds toarchiveListthe tag inqthe parameters. - User ExperienceWhen users perform filtering or search, keeping the filtering conditions visible on the page and clearly indicating the current selected filtering status can significantly improve user experience.
archiveFiltersTagsIsCurrentProperty provides good support in this aspect. - Pagination processing: The document list after filtering usually also needs to be displayed in pages, so don't forget to pair it with
paginationLabel. - Empty result prompt: Use
forLoopingemptyElegantly handle cases where no matching document is found, providing a friendly prompt to the user.
By the above method, the Anqi CMS makes it very flexible and powerful to filter and display specific document lists based on keywords, whether it is a simple site search or complex faceted navigation (multi-dimensional filtering), it can be easily achieved.
Common 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.htmlThe template file to implement. Place a search form in the template.actionthe attribute points to/search,inputfield'snameproperty is set toqThen, set the value of thearchiveListtags, andqparameter.urlParams.qTo retrieve the document list corresponding to the user input keyword. At the same time,paginationtags can be used to implement pagination of the search results.
2. Can I also filter by 'region' and 'house type' in addition to keyword search?Of course you can. The Anqi CMS'sarchiveListLabel supports receiving multiple URL query parameters as filtering conditions. If you have defined custom fields such as 'region' and 'house type' in your content model and these fields are marked as filterable, you just need to include these parameters in the URL at the same time, for example/search?q=公寓&地区=上海&房屋类型=住宅.archiveListIt will filter the documents based on all matching conditions. You can also use.archiveFiltersThese multi-dimensional filter options are generated on the front end by tags.
What will be displayed on the page if no documents are found after searching or filtering?InarchiveListWithin the tags,forWhat can you add in the loop?{% empty %}When there are no documents that match the filtering criteria.forThe loop will executeempty[en] Content within the block, rather than iterating over the document. This way, you can place a friendly prompt here, such as “Sorry, no documents matching the criteria were found.”