How to implement website in-site search and display article search results in AnQiCMS?

Calendar 👁️ 56

In website operation, the in-site search function plays a crucial role.It can not only help visitors quickly find the information they need and improve user experience, but also through the analysis of search data to understand user needs and optimize content strategies.AnQi CMS is an efficient content management system that provides a直观and powerful mechanism to implement website internal search and flexibly display search results.

The on-site search function of Anqi CMS is designed very practically.When a user enters a keyword to search on your website, the system will direct them to a dedicated search results page.This page is usually predefined in the template, it is responsible for receiving the user's query, and retrieving relevant information from all articles (or a specific content model) on the website based on the query content, ultimately presenting it to the user in a structured manner.

1. Prepare the search template file

To implement in-site search, first you need to prepare a namedsearch/index.htmlThe file. This file is recognized by AnQi CMS and used as the default page for handling all search requests.You can build search boxes, search result lists, pagination navigation and other elements according to your design requirements.

Indesign-director.mdmentioned in the documentsearch/index.htmlis the default search page template, which means all searches sent to/searchThe request path will be rendered by this template.

Second, build the user search form.

Allowing users to enter keywords is the first step in the search function. This is usually achieved through an HTML form. The form needs to specify the submission method asGET, and send the search request'sactionPoint to/searchPath. The core input box should be namedq,AnQi CMS'sarchiveListThe tag will automatically recognize this parameter as a search keyword.

To enhance the user experience, you can also allow the search box to retain the keywords entered by the user after submission, so that the user can know what they searched for previously. This can be done by{{urlParams.q}}This template variable can be easily implemented.

Here is a simple search form example.

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

After a user enters a keyword and submits a form, for example, searching for 'AnQi CMS', the URL may change to/search?q=安企CMS. The template system of AnQi CMS will captureqThe value of the parameter, and pass it to the subsequent label for displaying the result.

Three, display the list of article search results

Insearch/index.htmlIn the template, the core task is to display a list of articles related to the user's search keywords. Anqicms provides powerfularchiveListtags to complete this task.

archiveListlabel'stype="page"The parameter is crucial, indicating that we expect an article list that supports pagination. When you use it on the search pagearchiveListand the URL containsqparameters,archiveListthe tag will automatically readqThe value, and use it as a keyword to filter articles. It will match the title, description, and relevant fields of the article, and present articles containing the keyword.

You can choose fromarchiveListTag to retrieve the detailed information of each article, such as:

  • item.Title: Article title
  • item.Link: Article link
  • item.Description: Article Summary
  • item.CreatedTime: Article publication time (can bestampToDateformatted)
  • item.Views: Article views
  • item.Thumb: Article Thumbnail

When there are no search results,archiveListlabel's{% empty %}the block can be used to display friendly prompt messages.

Here is an example of the code to display the search results list:

{# page 搜索指定关键词分页列表展示 #}
<div>
{% archiveList archives with type="page" limit="10" %} {# limit 参数控制每页显示的文章数量 #}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <div>{{item.Description}}</div>
            <div>
                <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}}">
            <img alt="{{item.Title}}" src="{{item.Thumb}}">
        </a>
        {% endif %}
    </li>
    {% empty %}
    <li>
        抱歉,没有找到与您的搜索词相关的文章。请尝试其他关键词。
    </li>
    {% endfor %}
{% endarchiveList %}
</div>

4. Handling search results pagination

If there are many search results, the pagination function is essential. Anqi CMS'spaginationwith the tag andarchiveList type="page"Using labels together, it can conveniently build a perfect pagination navigation.

paginationThe label will be based onarchiveListThe total number of articles returned and the number of articles displayed per page, automatically generates links for "Home", "Previous Page", "Next Page", and middle page numbers.

paginationTags provide multiple useful fields, such as:

  • pages.TotalItemsTotal number of articles:
  • pages.TotalPagesTotal number of pages:
  • pages.CurrentPageCurrent page:
  • pages.FirstPageHome link object:
  • pages.PrevPagePrevious page link object:
  • pages.NextPage: Next page link object
  • pages.LastPage: End page link object
  • pages.Pages: An array containing middle page number links

The following is an example of pagination navigation code:

    {# 分页代码 #}
    <div>
        {% pagination pages with show="5" %} {# show 参数控制中间页码显示的数量 #}
            {# 首页 #}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" 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 class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">尾页</a>
        {% endpagination %}
    </div>

By following these steps, you can set up a fully functional, user-friendly in-site search system on the Anqi CMS website. The entire process does not require complex programming,

Related articles

How to display the associated Tag tag list on the AnQiCMS article detail page?

In website content operation, tags are important tools for connecting related content, enhancing user experience, and optimizing search engine rankings.AnQiCMS as an efficient content management system, naturally supports the association function between articles and tags.How can we clearly display these associated tags on each article's detail page to allow readers to quickly find more interesting content?This article will guide you in easily displaying the tag list on the article detail page of AnQiCMS.

2025-11-08

How to correctly render Markdown formatted article content in AnQi CMS and display it?

Today, with the increasing efficiency in content creation, Markdown is favored by content creators for its concise syntax and focus on the content itself.AnQi CMS understands this trend and provides powerful features that allow you to easily convert Markdown-formatted article content into exquisite HTML pages and support richer display effects, such as mathematical formulas and flowcharts.

2025-11-08

How to configure the lazy loading effect of images in the AnQiCMS article content?

In AnQiCMS, optimizing website loading speed is a key step to improving user experience and search engine rankings.When the article content contains a large number of images, these images will significantly increase the page loading time.Image lazy loading (Lazy Loading) is an efficient way to solve this problem, it can prevent images from loading until they enter the user's field of vision, thereby speeding up the initial rendering speed of the page.AnQiCMS as a content management system focusing on performance and SEO provides flexible support for lazy loading images in article content.You can configure the template simply

2025-11-08

How to implement 'Previous' and 'Next' document navigation on the AnQiCMS article detail page?

In Anqi CMS, implementing the "Previous" and "Next" navigation functions on the article detail page is a key link in improving user experience, guiding users to delve deeper into the website's content, and also helps optimize the internal link structure of the website, which is greatly beneficial for SEO performance.AnQiCMS has a powerful template system and flexible tag features, making this operation intuitive and efficient.### How to implement 'Previous' and 'Next' document navigation in AnQiCMS AnQiCMS has designed a series of convenient template tags specifically for retrieving information about adjacent documents in the article detail page

2025-11-08

How to display related article recommendations at the bottom of the AnQiCMS article detail page?

In AnQiCMS, adding a related article recommendation feature to the article detail page can not only effectively increase the user's stay time on the website, guide them to discover more interesting content, but also have a positive impact on the website's SEO performance.It is not difficult to achieve this function with the flexible and powerful template tag system provided by AnQiCMS. Understanding AnQiCMS Template Structure In AnQiCMS, the page layout and content display of the website are controlled by template files.

2025-11-08

How to build multi-condition filtering function for article list and display results in AnQiCMS?

In website operation, providing flexible multi-condition filtering functions for article lists can greatly enhance user experience and the discoverability of content.AnQiCMS (AnQiCMS) leverages its powerful content model and rich template tags to make building such features intuitive and efficient.Below, we will delve into how to step by step implement multi-condition filtering and display results of article lists in AnQiCMS.

2025-11-08

How to automatically generate and display a table of contents (TOC) on the AnQiCMS article content page?

In AnQiCMS, automatically generating and displaying the table of contents (TOC) for article content pages not only significantly enhances the user reading experience but also helps search engines better understand the article structure, thereby having a positive impact on SEO.With the powerful and flexible template system of AnQiCMS, it is simpler to achieve this function than you imagine.How does AnQiCMS support automatic directory generation?

2025-11-08

How to format the display of the publication and update time of articles in the AnQiCMS template?

In Anqi CMS website templates, displaying the publication and update time of articles is a key factor in improving user experience and content management efficiency.Clearly present this time information, which not only helps visitors quickly understand the timeliness of the content, but also assists search engines in better crawling and indexing.AnQiCMS provides a powerful and flexible template tag that allows you to format timestamps into various easily readable date and time formats as needed.### Core Mechanism: `stampToDate` tag The template system of Anqi CMS is built-in with a named

2025-11-08