How does AnQiCMS allow search results to be paginated on the page?

Calendar 👁️ 71

In AnQiCMS, implementing pagination for the website's search results is an important function for enhancing user experience and optimizing the website structure.AnQiCMS's powerful template tag system makes this process intuitive and efficient.By using reasonablyarchiveListandpaginationThese core tags allow you to easily build a fully functional search results page.

Core mechanism:archiveListTags and pagination types

AnQiCMS providesarchiveListTags act as a core tool to search and display all types of content on a website, including search results. When we need to implement pagination on the search results page, we just need toarchiveListSet in the labeltype="page"Parameter. The setting of this parameter enablesarchiveListIt not only returns the list of documents that meet the criteria, but also automatically handles the data required for pagination, laying the foundation for subsequent pagination navigation.

The handling of search keywords,archiveListBuilt-in tags,qParameter. You can directly specify the search term in the template, but a more intelligent and common practice is that when the user submits the keyword through the search form, AnQiCMS will extract it from the query parameters of the URL (such asq=关键词These search conditions are automatically recognized and applied, no additional manual handling is required in the template.This allows the content list to dynamically adjust according to the user's input keywords and provides an accurate data source for the subsequent pagination function.

Build a search form

A well-designed search function first requires a reasonable HTML search form.In AnQiCMS, the design of this form is similar to that of a conventional HTML form, the key is to set several core properties.

First, set themethodproperties of the"get"Make sure the search request is sent as GET to ensure that keywords can be passed through the URL. Second,actionThe property usually points to the system's search page path, for example"/search". Most importantly, the search keyword input box'snameattribute must be set to"q"This is the field name of the default search term recognized by AnQiCMS, ensuring that the system can correctly obtain the search term entered by the user.

Here is an example of a typical search form.

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

In this example,value="{{urlParams.q}}"The use can ensure that after the user submits the search, the search box still displays the keywords they entered previously, enhancing the user experience.

Display the search results list

The display of search results usually occurs in dedicated template files. According to the AnQiCMS template conventions, for the search results page, the system defaults to searching for/templateUnder the directorysearch/index.htmlFile. All of your search result display logic should be concentrated in this file.

In this template, we will use it again.archiveListTags to retrieve and render documents matching the search criteria. Combined with what was mentioned previouslytype="page"parameter,archiveListWill return a list of documents containing pagination information.limitParameters are used to control how many search results are displayed per page.

ByforLoop througharchivesVariables, we can show the title, description, and link information of each search result one by one. If the current search result is empty,{% empty %}The content within the tag will provide a friendly prompt.

The following is an example code snippet showing a list of search results:

<div>
{% archiveList archives with type="page" limit="10" %} {# q参数无需手动指定,系统会从URL自动获取 #}
    {% 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>

Implement elegant pagination navigation

After displaying the search results list, pagination navigation is an indispensable link to facilitate users to browse more results. AnQiCMS providespaginationtags, which can intelligently identify according toarchiveListThe tag returns pagination data, automatically generating complete page navigation.

paginationThe tag usually returns one.pagesAn object that contains the home page, previous page, next page, last page, and an array of middle page numbers. You can use this information to flexibly build pagination links.

showThe parameter allows us to control the number of page numbers displayed in the middle page number area. For example,show="5"it will display 5 page numbers around the current page to help users quickly locate. By traversingpages.Pagesthe array, combineditem.IsCurrentProperty, can highlight the current page number to provide a clear navigation experience.

Here is a typical code example of pagination navigation.

<div>
    {% pagination pages with show="5" %}
    <ul>
        <li>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>
        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
        {% if pages.PrevPage %}
            <li class="page-item"><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
        {% endif %}
        {% for item in pages.Pages %}
            <li class="page-item {% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
        {% endfor %}
        {% if pages.NextPage %}
            <li class="page-item"><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
        {% endif %}
        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
    </ul>
    {% endpagination %}
</div>

By following these steps, your AnQiCMS website can have a complete and user-friendly search result pagination display function. This not only improves the browsing experience of users on the website but also helps search engines

Related articles

How to implement pagination functionality for article or product lists in AnQiCMS templates?

How to implement pagination for article or product lists in AnQiCMS template?For any content management system, effectively managing and displaying a large amount of content is a core requirement.When the number of articles or products on a website increases day by day, if there is no reasonable pagination mechanism, users may feel tired while browsing, and the website's loading speed may also be affected.

2025-11-08

How does AnQiCMS filter and display content based on article recommendation attributes (such as headline, recommended)?

In content operation, effectively highlighting and displaying important articles is the key to improving user experience and guiding traffic.AnQiCMS (AnQiCMS) fully understands this point, therefore, it provides a flexible article recommendation feature, allowing you to mark it based on the importance of the content or specific use, and accurately filter and display it on the website front end.

2025-11-08

How to exclude content of a specific category from the article list?

In website content operation, we often encounter such needs: we hope to display most of the content on the article list page, but articles of certain specific categories are not listed here.For example, you may have a "Company Announcement" category that you only want to display on a separate page, or some articles for internal reference that you do not want to appear in the regular article list facing the public.AnQiCMS (AnQiCMS) provides a very flexible and intuitive way to handle this situation, allowing you to accurately control the display of content on the front end.The Anqi CMS through its powerful template tag system

2025-11-08

How to set the number of articles or products displayed per page in AnQiCMS?

In website operation, especially when managing pages that require a large amount of content display, such as article lists and product display pages, how to efficiently control the number of items displayed per page directly affects user experience and page loading speed.AnQiCMS provides a flexible and powerful mechanism to meet this requirement, it allows you to customize the display of each page according to different page and content types through fine-grained control at the template tag level.The Anqi CMS can provide this flexibility because it closely integrates the display logic of the list content with the template design

2025-11-08

How can articles be sorted by views in the AnQiCMS template?

In AnQiCMS, content management is not limited to publishing and organizing, how to effectively display these contents, especially placing popular articles in prominent positions, is the key to improving user experience and website activity.This article will introduce in detail how to sort the article list by views in the AnQiCMS template, making hot content naturally stand out.

2025-11-08

How to display a list of articles published by a specific author in AnQiCMS?

In AnQiCMS, efficiently managing and displaying content is the core of website operation.Sometimes, you may need to display all the articles published by a specific author, such as creating an author column, a team member introduction page, or a personal portfolio.AnQiCMS's powerful template tag system provides a flexible way to meet this requirement, allowing you to easily filter and display a list of content from specific authors.This article will introduce you to how to display a list of articles published by a specific author in AnQiCMS, helping you better organize your website content.##

2025-11-08

How to filter and display a list of documents in AnQiCMS using custom parameters?

In AnQiCMS (AnQiCMS), when managing and displaying a large amount of content, we often need to go beyond simple categories and tags to achieve more refined content filtering.For example, a real estate website may need to filter listings by "type", "area", and "price range";An e-commerce website may need to filter products by color, size, and brand.AnQiCMS provides a powerful custom parameter feature, making it very intuitive and efficient to implement this advanced filtering.Below, we will gradually understand how to use AnQiCMS

2025-11-08

How to display all documents under the current category and its subcategories in AnQiCMS template?

In AnQiCMS template design, flexibly displaying content is the key to website operation.When you need to display articles under a category page not only, but also hope to present all subcategory articles together, or display them in a more structured way, AnQiCMS provides powerful template tags to meet these needs.This article will introduce in detail how to implement this feature in your AnQiCMS template.### Understanding AnQiCMS's classification and document mechanism In AnQiCMS, content is usually organized under "document model" and "classification"

2025-11-08