How to implement pagination for article lists, product lists, or Tag lists?

Calendar 👁️ 71

Managing website content, especially when the amount of content becomes increasingly large, how to allow visitors to quickly find the information they need while maintaining smooth page loading is an important issue.AnQiCMS was designed with this in mind from the beginning, it provides a set of intuitive and powerful pagination features that allow your article list, product list, and even Tag list to achieve elegant pagination display.

We all know that when there are many articles or products under a category, displaying them all on a single page not only slows down the loading speed but also makes users feel confused in the massive amount of information.The pagination feature exactly solves this problem, it splits a large amount of content into several small pages, with each page displaying only a portion of the content, thereby optimizing user experience and website performance.

Step 1: Prepare the content list and enable pagination mode

In Anqi CMS, to implement pagination for articles, products, or any other content model-based list, you first need to use the corresponding list tags to retrieve the data. For example, with an article list, we usually usearchiveListLabel. The function of this label is to obtain a list of document data under specified categories or specific conditions.

The key is that you need to explicitly tell the system that this list needs to be paginated. This is done byarchiveListSet in the labeltype="page"Parameters can be used to achieve this. At the same time, you canlimitParameters can be used to control how many items are displayed per page.

For example, if you want to display the latest 10 articles on a page and enable pagination, your template code might look like this:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h3>{{item.Title}}</h3>
            <p>{{item.Description}}</p>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </a>
    </li>
    {% empty %}
    <li>
        当前没有任何文章内容。
    </li>
    {% endfor %}
{% endarchiveList %}

In this code block,archivesIt is a variable defined by us, which will carry fromarchiveListThe data of the current page of articles obtained from the tag.type="page"Declared that the list needs pagination, whilelimit="10"It limited the display of 10 articles per page. When there is no content,{% empty %}the part will kindly prompt the visitor.

Second step: introduce pagination navigation tags

Only getting pagination data is not enough to provide a complete user experience. Visitors still need a pagination navigation to switch between different pages. At this time, the built-in of Anqi CMSpaginationTags come into play. This tag is specifically used to render pagination navigation links and states.

paginationTags are usually witharchiveListWhen used in conjunction with list tags, it automatically recognizes the pagination information of the current list and generates the corresponding navigation links. You canshowThe parameter controls how many page number buttons are displayed in the pagination navigation, for exampleshow="5"This means that up to 5 consecutive page numbers can be displayed.

A complete pagination navigation usually includes elements such as Home, Previous page, specific page numbers, Next page, and End page, etc., to provide comprehensive navigation capabilities. Below is an example of combining list content with pagination navigation:

<div>
    {# 文章列表内容区域 #}
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <div class="article-item">
            <a href="{{item.Link}}">
                <h2>{{item.Title}}</h2>
                <p>{{item.Description}}</p>
                <div class="meta">
                    <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 src="{{item.Thumb}}" alt="{{item.Title}}">
            </a>
            {% endif %}
        </div>
        {% empty %}
        <p>当前分类下暂时没有文章。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 分页导航区域 #}
    <div class="pagination-nav">
        {% pagination pages with show="5" %}
            {# 首页链接 #}
            <a class="page-link {% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>

            {# 上一页链接 #}
            {% if pages.PrevPage %}
            <a class="page-link" href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
            {% endif %}

            {# 中间页码链接 #}
            {% for item in pages.Pages %}
            <a class="page-link {% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
            {% endfor %}

            {# 下一页链接 #}
            {% if pages.NextPage %}
            <a class="page-link" href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
            {% endif %}

            {# 末页链接 #}
            <a class="page-link {% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>

            <span class="page-info">
                总计 {{pages.TotalItems}} 条,共 {{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页
            </span>
        {% endpagination %}
    </div>
</div>

This code first displays the list content, followed by the pagination navigation.pagesThe variable contains all the information needed for pagination, including the current page number, total number of pages, total number of entries, as well as links to the first page, last page, previous page, next page, and middle page numbers, and the current status. By traversingpages.PagesYou can flexibly render page number buttons.item.IsCurrentBoolean values can help you easily judge and highlight the current page.

Other pagination applications of list types

This pagination mechanism of AnQi CMS has high versatility.This means that, whether it is a product list, Tag list, or comment list, you can use the same logic to implement pagination.

  • Product list pagination:If you want to paginate the product list, just need toarchiveListin the labelmoduleIdThe parameter is set to the ID corresponding to the product model (assuming the product model ID is 2), and other pagination parameters and logic remain unchanged.
  • Tag list pagination:For documents under a specific Tag, you can usetagDataListtag, set as welltype="page"andlimitthe parameter and cooperatepaginationtags to display pagination.
  • Comment list pagination:The comment list usescommentListtags, with the help ofarchiveId(The article/product ID of the comment) as welltype="page"andlimitto implement pagination.

The core idea is that as long as it supportstype="page"the list label of the parameter, it can be perfectly matched withpaginationthe tag.

Advanced Application: Pagination of Search Results

When your website provides a search function and the number of search results is large, pagination is also indispensable. The search result pagination function of Anqi CMS is very intelligent and convenient.

On the search page (usually the default path is/search)archiveListthe tag can automatically read the URL query parameters inq(search keyword), and filter the content according to this keyword. You do not need to inarchiveListSpecify manually in the tagqThe system will complete it for you.

Here is an example of a simple search form:

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

After submitting the form, the user will be taken to/search?q=您的关键词such a URL./searchIn the template, you can use it as shown in the article list abovearchiveListcooperatepaginationto display the search results of pagination.

**Practice and Precautions

  1. URL static optimization:To enhance SEO effectiveness and user experience, it is recommended to configure pseudo-static rules for pagination URLs. The pseudo-static management function of AnQi CMS supports including variables in the rules.{page}For example,/{module}-{id}.htmlor `/ {catname}-{page

Related articles

How to display a list of related articles based on the article's Tag (label)?

In a content management system, effectively utilizing tags (Tag) to organize and associate articles is a key factor in improving user experience and the efficiency of content discovery.AnQiCMS provides a powerful and flexible tag feature, allowing us to easily display related content lists based on the tags of the articles. ## Understanding AnQiCMS Tag Function AnQiCMS Tag function is not just for adding keywords to articles, it is more like a way to associate content across categories and models.By adding tags to the article, we can group those with similar themes

2025-11-08

How to display a list of friend links in the sidebar or footer area of a website?

AnQi CMS provides a set of intuitive and powerful features to help us easily manage website content.Among them, the link to friends is an important part of the external connection of the website, which not only helps the website's SEO performance, but also provides users with more valuable jump links.This article will provide a detailed introduction on how to flexibly display the friend links list in the sidebar or footer area of your website. ### Manage friend links in the background Before displaying the friend links on the website front end, we first need to configure them in the Anqi CMS backend.To manage the friend links, you can log in to the backend

2025-11-08

How to implement lazy loading of image content on article detail pages to improve page loading speed?

In today's fast-paced online environment, website loading speed is a key factor in user experience and search engine rankings.For an article detail page containing a large number of images, optimizing the image resources is particularly important.By implementing lazy loading of images, we can significantly improve the initial loading speed of the page, allowing visitors to see the content faster, thereby providing a better experience.The AnQiCMS (AnQiCMS) has fully considered the performance optimization needs of the website design, providing a simple and efficient way to achieve lazy loading of images on article detail pages.###

2025-11-08

How to ensure that the content of the article is rendered correctly as HTML on the front-end page if it uses Markdown format?

In Anqi CMS, master Markdown: Ensure content is elegantly rendered as HTML Markdown, as a lightweight markup language, is increasingly favored by content creators for its simplicity, efficiency, and ease of use.It allows us to focus on the content itself without being distracted by complex layout tools.

2025-11-08

How can I display the list of articles under the category page and also show the category's Logo or Banner image at the same time?

Managing and displaying categories in Anqi CMS is a key step in building a well-structured, user-friendly website.The category page not only helps users find the content they are interested in quickly, but also, with the help of carefully designed visual elements such as logos or banner images, it can effectively enhance the brand image and user experience.This article will detail how to implement these functions on the category page of Anqi CMS.

2025-11-08

How to display the global TDK (Title, Keywords, Description) information of the website?

## Optimizing Website Front: Display and Application of TDK Information in AnQi CMS In website operation, TDK (Title, Keywords, Description) is an indispensable basic element for Search Engine Optimization (SEO).They are like the 'business card' of a website, directly telling search engines about the theme, core content, and most important keywords of your page, thereby affecting the ranking and click-through rate in search results.

2025-11-08

How to precisely control the display content, level, and selected status of a website navigation menu?

Website navigation, like a signpost of a website, a clear and intuitive navigation system can greatly enhance the user experience and help visitors quickly find the information they need.At the same time, a good navigation structure is also crucial for search engines to understand the hierarchy of website content, to effectively crawl and rank.In AnQi CMS, we can flexibly and accurately control the display content, level, and selected status of the website navigation, making it both beautiful and practical.

2025-11-08

How to add and display dynamic breadcrumb navigation on a webpage?

In modern web design, breadcrumb navigation plays a crucial role.It is like a 'footprint' of the user on the website, clearly showing the position of the current page in the overall website structure, making it easy for visitors to understand, thereby greatly enhancing the usability and user experience of the website.At the same time, a reasonably set breadcrumb navigation also helps search engines better understand the structure of the website, which is very beneficial for SEO optimization.For users who use AnQiCMS to manage websites

2025-11-08