How to implement pagination for document list, related documents, and search results using the `archiveList` tag?

Calendar 👁️ 57

Manage website content in Anqi CMS, whether it's blog articles, product displays, or news information, efficient list display is indispensable.When the amount of content gradually increases, how to elegantly present a large number of documents and ensure that users can easily browse and search has become a focus for operators. At this time,archiveListThe tag and its page function have become a powerful tool in our hands, it can not only implement pagination of ordinary document lists, but also be applied flexibly to the display of related documents and search results.

Document list pagination display

Imagine that your website has a "Latest Articles" or "Product Center" page that contains hundreds or even thousands of items.If there is no pagination, users may need to scroll endlessly to find the information they want, which undoubtedly will greatly affect the user experience.AnQi CMS'sarchiveListTags, which are born to solve this problem

To implement document list pagination display, we mainly usearchiveListlabel'stype="page"The parameter tells the system that we want to retrieve a paginated collection of documents. At the same time,limitThe parameter is used to set how many documents are displayed per page, for example,limit="10"indicating that 10 documents are displayed per page.

This code snippet shows how to retrieve and display a list of documents under a category in a template, along with pagination functionality:

{# 假设我们想显示分类ID为1的文章列表,每页显示10条 #}
<div>
    {% archiveList archives with type="page" categoryId="1" limit="10" order="id desc" %}
        {% for item in archives %}
        <div class="document-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
            <small>发布于: {{stampToDate(item.CreatedTime, "2006-01-02")}} | 浏览量: {{item.Views}}</small>
            {% if item.Thumb %}
            <a href="{{item.Link}}"><img src="{{item.Thumb}}" alt="{{item.Title}}"></a>
            {% endif %}
        </div>
        {% empty %}
        <p>当前分类下暂时没有文档。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 分页导航区域,通常紧跟在文档列表之后 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            {# 显示“首页”链接 #}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
            {# 显示“上一页”链接(如果存在) #}
            {% if pages.PrevPage %}
            <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
            {% endif %}
            {# 循环显示中间的页码链接,例如:1 2 3 4 5 #}
            {% 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}}">{{pages.NextPage.Name}}</a>
            {% endif %}
            {# 显示“尾页”链接 #}
            <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        {% endpagination %}
    </div>
</div>

In this code block,archiveListResponsible for retrieving data,archivesThe variable contains all the document data on the current page, and we display it byforloop traversal. Whilepaginationthe tag is responsible for generating page navigation,pagesThe variable provides information such as total number of pages, current page, first page, last page, previous page, next page, and middle page numbers, allowing you to flexibly build various styles of pagination bars.show="5"The parameter controls the maximum number of middle page links displayed. In addition, you can alsomoduleIdspecify a content model (such as articles or products), or useorderParameters such asorder="views desc"Sort by view count to refine the document filtering and sorting.

Elegant presentation of the related document list

After a user reads an excellent article, they will naturally want to see more related content. In Anqi CMS,archiveListTags can also help us achieve this, but here it is usually not pagination, but displaying a fixed number of related document lists.

To get related documents, we willarchiveListoftypethe parameter to"related". The system will intelligently recommend the most relevant content based on the current document's keywords or categories.limitParameters are particularly important here, as they directly control the number of related documents displayed.

Here is an example of displaying related articles on the document detail page.

{# 假设这是在文档详情页的模板中 #}
<div class="related-documents">
    <h3>相关推荐</h3>
    <ul>
        {% archiveList archives with type="related" limit="5" %} {# 获取最多5条相关文档 #}
        {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
                <span>{{item.Title}}</span>
            </a>
        </li>
        {% empty %}
        <li>暂无相关文档。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

In this scenario, we usually do not paginate related documents, but instead display a curated small list.limit="5"Ensure the page layout is simple and not disturbed by too much content. You can also try to control the related logic more accurately if you wish.like="keywords"Or based on keyword matchinglike="relation"(Only shows documents manually associated in the background).

Pagination implementation on the search results page.

Your website content is getting richer and richer. How can users quickly find the information they need? An efficient search function is indispensable. Anqi CMS'sarchiveListThe tag can also perfectly handle the display and pagination of search results.

On the search results page,archiveListThe tag is also usedtype="page"to enable pagination. The key is to introduceqA parameter, it will match the document title based on the user's input keyword. When the user submits a query in the search box, the page URL usually includesq=关键词such a parameter,archiveListThe URL parameter will automatically be read to perform a search.

First, you need a search form:

<form method="get" action="/search"> {# 假设搜索结果页的URL是/search #}
    <input type="text" name="q" placeholder="请输入搜索关键词" value="{{urlParams.q}}"> {# value="{{urlParams.q}}"用于保留搜索框中的关键词 #}
    <button type="submit">搜索</button>
</form>

Next, in/searchPage (or the search result template file you define), you can display the search results like this and implement pagination:

`twig

<h3>搜索结果: {{urlParams.q}}</h3>
{% archiveList archives with type="page" limit="10" %} {# 这里不需要显式指定q,因为它会从URL中自动读取 #}
    {% for item in archives %}
    <div class="search-result-item">
        <h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
        <p>{{item.Description}}</p>
        <small>分类: {% categoryDetail with name="Title" id=item.CategoryId %}</small>
    </div>
    {% empty %}
    <p>抱歉,没有找到与“{{urlParams.q}}”相关的文档。</p>
    {% endfor %}
{% endarchiveList %}

{# 搜索结果的分页与普通列表分页相同 #}
<div class="pagination-controls">
    {% pagination pages with show="5" %}
        <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {% if pages.PrevPage %}
        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name

Related articles

How to retrieve and display specific fields (such as title, content, image) of the document detail page using the `archiveDetail` tag?

On Anqi CMS built websites, each document detail page is the key to displaying core content and attracting visitors to stay.To ensure that these pages can efficiently and flexibly present important information such as article titles, content, images, etc., it is particularly important to understand and make good use of the `archiveDetail` tag.It is the powerful tool that precisely locates and flexibly displays these core data.## Master the `archiveDetail` tag: Accurately locate and display document detail content When you create an article or product detail page in AnQiCMS

2025-11-07

How to create and display independent pages such as 'About Us' and 'Contact Us' in a single-page management?

In website operation, independent pages like "About Us" and "Contact Us" are essential basic content.They not only help visitors quickly understand the company and provide contact information, but are also a key window for building trust and showcasing the brand image.AnQiCMS (AnQiCMS) provides us with an intuitive and powerful single-page management function, making it easy and efficient to create and maintain these pages. Next, we will explore how to create, display these independent pages, and integrate them into the website navigation in Anqi CMS.### Step 1

2025-11-07

How to manage image resources and control their display in content (such as Webp, automatic compression, thumbnails)?

In website operation, images are indispensable elements that attract users and convey information.However, managing and optimizing these image resources is often a headache, as it directly affects the website's loading speed, user experience, and even the search engine optimization (SEO) effect.Fortunately, AnQiCMS provides a series of powerful and flexible features for image management, allowing you to easily cope with these challenges.Why is image management so important? Imagine a user opening your website and being unable to see the full content due to slow image loading

2025-11-07

How does mobile end address configuration affect mobile users' access and display of website content?

With the popularity of smartphones, mobile devices have become the mainstream way for users to access websites.The performance of the website on mobile directly affects user experience and search engine rankings.In Anqi CMS, the configuration of the mobile end address is the key link to ensure that the website can provide mobile users with a **good access experience.Flexible and diverse options are provided by Anqi CMS for mobile adaptation, mainly including adaptive, code adaptation, and PC+mobile independent site modes.When we choose the adaptive or code adaptation mode, the website will share a set of URL addresses on both PC and mobile ends

2025-11-07

How to get and display the title, description, thumbnail, and associated content of the `categoryDetail` tag?

Manage and display website content in Anqi CMS, the `categoryDetail` tag plays a crucial role.It is like the conductor of your website content display, able to accurately obtain and present all the detailed information of a specific category, whether it is the title, description, thumbnail, or deeper related content, it can help you a lot. ### The core function of the `categoryDetail` tag In simple terms, the mission of the `categoryDetail` tag is to obtain detailed data for a single category.

2025-11-07

How to get and display the title, content, and image of a single page using the `pageDetail` tag?

## AnQi CMS `pageDetail` tag: Easily obtain and display single page information Single pages (such as "About Us", "Contact Us", "Terms of Service", etc.) play an indispensable role in website content management.They usually carry stable, core information that does not need to be updated as frequently as articles or products.AnQi CMS provides an efficient and flexible tool for displaying this type of page - the `pageDetail` tag.Mastering the use of this tag will allow you to be proficient in template development, easily presenting beautifully designed single-page content

2025-11-07

How to dynamically generate the page Title, Keywords, and Description using the `tdk` tag to optimize SEO display?

In website operations, Search Engine Optimization (SEO) is a key link to improve website visibility and attract natural traffic.Among them, the page's `Title` (title), `Keywords` (keywords), and `Description` (description), abbreviated as TDK, are important signals for search engines to understand the content of the page and determine the ranking.An excellent TDK setting can make your website stand out in a sea of information.AnQiCMS (AnQiCMS) fully understands the importance of TDK and has integrated powerful TDK management functions into the system design from the very beginning

2025-11-07

How to build a multi-level navigation menu using the `navList` tag and display it on the front end?

AnqiCMS provides powerful and flexible configuration options for website navigation, allowing you to easily build multi-level navigation menus and customize the display on the front-end website according to business needs.Whether it is a simple single-layer menu or a complex multi-level navigation with dropdown content, the `navList` tag can help you a lot. To implement multi-level navigation, we first need to complete the configuration of the navigation structure in the background management system, which lays the foundation for the display on the front end.

2025-11-07