How to implement keyword search and filtering display on article list or search result pages?

Calendar 👁️ 50

How to make visitors quickly find the content they need among the vast amount of information on our website is undoubtedly a key to improving user experience and content marketing effectiveness.AnQiCMS (AnQiCMS) fully understands this, and therefore provides a powerful and flexible mechanism to help us easily implement the keyword search and content filtering functions on the article list or search results page.

The implementation of this feature is mainly centered around the core template tags of Anqi CMS, allowing us to transform the content of the background management through the exquisite design of the front-end template into a user-friendly interactive interface.

The core of content display: document list

In Anqi CMS, whether it is articles, products, or other custom content models, their list display cannot do withoutarchiveListThis powerful template tag. It is the cornerstone of content presentation and can flexibly retrieve and organize content according to our needs.

When we want to display a content list on a page, we usually use it like this:

{% archiveList archives with type="page" limit="10" %}
    {# 在这里循环展示每一篇文章或产品,例如: #}
    {% for item in archives %}
        <a href="{{item.Link}}">{{item.Title}}</a>
        <p>{{item.Description}}</p>
    {% endfor %}
{% endarchiveList %}

here,type="page"It indicates that we want the list to be pageable, whereaslimit="10"it controls the number of items displayed per page.archivesis the variable name we give to the content list, convenient toforcall in the loop.

implement keyword search function

Allow visitors to search for content by entering keywords is an important step to improve the practicality of the website. Anqi CMS has built-in support for search keywords inarchiveListtags.

We just need to place a simple search form on the page and pass the search keywords through the URL parametersqto the server. Anqi CMS will intelligently identify thisqand it will take effect in thearchiveListWhen tagging content, it automatically filters out content with the keyword in the title.

A typical search form might look like this:

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

here,action="/search" Usually points to the search results page of our website,name="q"It is the agreed keyword parameter.value="{{urlParams.q}}"The usage is very clever, it allows the search box to retain the previously entered keywords after searching, providing a better user experience. After submitting the form, for example, if you enter "Anqi CMS", the URL may become/search?q=安企CMSAt this time, we search for the result page ofarchiveListThe tags will naturally filter out relevant content.

Deep optimization: content filtering and classification

In addition to direct keyword search, more refined content filtering can help visitors quickly narrow down the scope and find the most matching needs.This is usually based on content classification, tags, or custom attributes.

Of Security CMSarchiveFiltersThe label is designed to build such filtering interfaces. It can dynamically generate filtering options based on the custom fields defined in the backend content model.

Imagine you have a product model where you define custom fields such as "color", "size", and so on. ByarchiveFilterstags, you can display the filtering options of these fields on the front end:

{% archiveFilters filters with moduleId="1" allText="全部" %}
    {% for item in filters %}
        <div>
            <span>{{item.Name}}: </span>
            {% for val in item.Items %}
                <a class="{% if val.IsCurrent %}active{% endif %}" href="{{val.Link}}">{{val.Label}}</a>
            {% endfor %}
        </div>
    {% endfor %}
{% endarchiveFilters %}

In this code block:

  • moduleId="1"Specify the filter parameters for the content model we want to retrieve (e.g., article model ID is 1).
  • allText="全部"Set the display text for the "All" option.
  • filtersThe variable will include all filterable parameter groups, eachitemrepresents a custom field (such as “Color”).*
  • item.Itemswhich includes all the optional values for the field (such as “Red”, “Blue”).*
  • val.LinkIs an Anqi CMS automatically generated filter link, clicking it will add the corresponding filter parameters to the URL.
  • val.IsCurrentUsed to determine whether the current option is selected, convenient for us to add to the selected items.activeStyle.

When a visitor clicks on a filter option, the URL will include the corresponding parameters (for example/list?color=red&size=large), while the previous one mentionedarchiveListLabels can automatically identify and apply these filtering conditions when retrieving content, displaying precise matching results.

In addition to custom field filtering, we can alsocategoryIdThe parameter is inarchiveListFilter content directly by category, or usetagDataListtags to display articles under specific tags, all of these are effective means of content filtering.

building a user-friendly filtering interface

A well-designed, intuitive and easy-to-use filter interface, which can greatly enhance the user experience. CombinedarchiveFiltersandarchiveList, we can create a comprehensive filter page.

Generally, we willarchiveFiltersLabels placed at the top or side of the page, used to display filter options. AndarchiveListTags are used to display the filtered content list. Both work together to respond to query parameters in the URL.

For example, on a product list page, visitors can first filter througharchiveFiltersSelect "Color" as "Blue","Size" as "Large", page refreshed,archiveListall blue large products will be displayed automatically. At the same time,paginationTags can also ensure that pagination functions normally in filtered results.

Pagination display: A necessity for large lists.

For any list that may produce a large number of results, pagination is essential. Anqi CMS'spaginationwith the tag andarchiveListwork closely together, can elegantly handle pagination logic.

WhenarchiveListSet totype="page"When, the page can be usedpaginationLabels to render pagination navigation. It provides links for 'Home', 'Previous page', 'Next page', 'End page' as well as links to the middle page numbers, and can automatically judge the current page and add links to it.activestatus。“

{% pagination pages with show="5" %}
    <a href="{{pages.FirstPage.Link}}">首页</a>
    {% if pages.PrevPage %}
        <a href="{{pages.PrevPage.Link}}">上一页</a>
    {% endif %}
    {% for item in pages.Pages %}
        <a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
    {% endfor %}
    {% if pages.NextPage %}
        <a href="{{pages.NextPage.Link}}">下一页</a>
    {% endif %}
    <a href="{{pages.LastPage.Link}}">尾页</a>
{% endpagination %}

BypagesVariable, we can get all the information of the current page, such as total number of items, total number of pages, and current page

Related articles

How to add watermarks to images on the AnQiCMS website to protect original content?

In today's increasingly rich digital content, protecting the copyright of original works is particularly important, especially for visual content such as images.When your website publishes a large number of carefully crafted images, if they are not protected, it is easy for others to copy and repost them arbitrarily, which not only infringes on your labor results but also weakens the uniqueness of the content.Adding a watermark to an image is a simple and effective means of copyright protection, which can clearly assert ownership of the content without affecting the beauty of the image, effectively deterring unauthorized use.Anqi CMS as a highly efficient

2025-11-07

How to display the filing number and copyright information at the bottom of the website in AnQiCMS?

During the operation of a website, whether it is to meet the requirements of laws and regulations or to enhance the professionalism and user trust of the website, clearly displaying the filing number and copyright information at the bottom of the website is an important aspect.AnQiCMS as an efficient content management system provides a very flexible and intuitive way to configure and display these key information. Next, we will introduce step by step how to set and display the filing number and copyright information at the bottom of the AnQiCMS website.### The first step: Fill in the filing number and copyright information in the background First

2025-11-07

How to display the name and link of the current article's category in a frontend template?

In website content operation, the classification information of articles not only helps users quickly understand the content attribution, but also is the key to improving the website navigation experience and search engine optimization (SEO) effect.For friends who use AnQiCMS to build websites, it is a very practical and basic requirement to accurately display the name of the category to which each article belongs and provide a link.AnQiCMS provides powerful and flexible template tags, allowing us to easily achieve this function.### Skillfully Utilize `archiveDetail`

2025-11-07

Does AnQiCMS website support automatically converting uploaded images to WebP format to speed up display speed?

The loading speed of a website is an important factor for user experience and search engine optimization.Among them, images play an important part in the page content, and their loading efficiency has a significant impact on the overall performance of the website.WebP is a modern image format, compared to traditional JPEG, PNG, it can provide similar or even higher image quality with smaller file size, thereby significantly speeding up web page loading speed.AnQiCMS as a content management system that focuses on efficiency and performance, fully considers the optimization needs of the website in image processing.For "AnQiCMS"

2025-11-07

How to get and display the Tag list of articles in the front-end template of AnQiCMS?

AnQiCMS as an efficient and flexible content management system, provides a wealth of features to help operators manage and display website content.Among them, the Tag tag function of the article is an important factor for optimizing content organization, improving user experience and SEO effects.Understand how to obtain and display these tags in front-end templates, which is crucial for building a website with comprehensive functions.### In AnQiCMS backend management tags Before delving into the front-end template, let's briefly review how tags work in the AnQiCMS backend

2025-11-07

How to display a custom page template independently on a specific page (such as About Us)?

Hello! When using AnQi CMS to build a website, we often encounter such needs: some specific pages, such as 'About Us', 'Contact Us', or some special topic pages, need to have a completely different layout and design from other pages on the website.Luckyly, AnQi CMS provides a very flexible solution for this, allowing you to easily specify independent custom templates for these pages.AnQi CMS with its efficient features based on the Go language and support for Django template engine syntax, brings great convenience and customizability to content display

2025-11-07

How to determine if a variable is empty in AnQiCMS template and display default content?

In website content operation, data integrity and the elegance of display are crucial.We often encounter such situations: some fields of data may be missing for various reasons, such as an article may not have an illustration, a product may not have a detailed description, or a custom field may not be filled in.If the template code does not perform the corresponding null value judgment, it may result in blank pages on the page, affecting the aesthetics, or may even cause template rendering errors, affecting the user experience.AnQiCMS with its efficient architecture based on the Go language and similar to Django

2025-11-07

How to implement safe output of HTML tags in article content to avoid XSS attacks?

In AnQiCMS, we not only pursue efficient and flexible content management, but also regard website security as a core element.In daily content creation and template development, a seemingly simple HTML tag output actually hides potential security risks, the most common of which is cross-site scripting (XSS) attack.Understanding how AnQiCMS processes HTML output and mastering security practices is crucial for building a robust and reliable website.How does AnQiCMS handle HTML content output?In AnQiCMS template rendering mechanism

2025-11-07