How to set the display quantity and offset for the `archiveList` tag in AnQiCMS to achieve pagination?

Calendar 👁️ 62

As an experienced website operations expert, I am well aware that an efficient and flexible list display method is crucial for user experience and website performance.AnQiCMS (AnQiCMS) has provided us with great convenience with its powerful template tag system.archiveListLabel, cleverly set the display quantity and offset to achieve smooth pagination effects.

Mastering AnQi CMS'sarchiveListLabel: The art of efficient pagination and content presentation.

In AnQiCMS,archiveListLabels are undoubtedly the core of content display.It can help us retrieve a list of various types of documents such as articles, products from the database, and sort, filter, and display them according to our needs.archiveListSeveral key parameters of the tag, especiallytypeandlimit.

archiveList: The foundation of content acquisition and the number of items displayed per page

First, let's understandarchiveListHow labels work.When you need to display a series of documents on a page, this tag is your helpful assistant.It defines the range and characteristics of the content you want to retrieve through a series of parameters.

The most critical step to achieve pagination effect is to ensurearchiveListlabel'stypethe parameter is set to"page". Whentypeis set to"page"at this time, AnQiCMS understands that you want to get a paginated collection of documents, rather than a simple static list.

Next,limitThe parameter plays a role in setting the number of items displayed per page. By means oflimit="10"Such settings, we inform the system to display only 10 documents per page. When the user switches to the second page, the system will use thislimitThe value and the current page number, automatically calculate how many documents need to be skipped (i.e., the offset) and retrieve the next page's content. This means that when usingtype="page"When paginating, we usually do not need to manually calculate or specify an offset; the system will handle it intelligently for you.

It is worth mentioning,limitThe parameter also has the function of "offset" in non-paging scenarios. If you just want to display a static list on a single page and want to skip the first few data, you canlimitis set to"offset,count"The form, for examplelimit="2,10".This indicates starting from the 2nd data (index starts from 0, which is actually the 3rd), and fetching the next 10 data.But in the context of pagination, we mainly use it to define the "number of items per page".

excepttypeandlimit,archiveListIt also provides rich filtering and sorting features, such as throughmoduleIdSpecify the content model, throughcategoryIdSpecify the category, or throughorder="views desc"Arrange according to the number of views in descending order, all of these can help you more accurately control which content is displayed.

paginationTo visualize pagination navigation:

Just pass through.archiveListThe pagination data is not enough, we also need an intuitive navigation interface that allows users to easily jump between different pages. At this time, AnQiCMS'spaginationThe label appears. It can generate page information according toarchiveListAutomatically render "Previous page

paginationThe most commonly used parameter is for the tagshowIt determines how many page number links are displayed at the same time in page navigation. For example, setshow="5"Can make the navigation display 5 page numbers around the current page, such as '1 2 [3] 4 5'.This helps maintain the conciseness of pagination navigation, avoiding the display of a long dense string of page numbers when the content is vast.

CombinearchiveListandpaginationWe can build a complete, dynamic pagination list. Below is a typical template code example showing how these two tags work together:

{# 假设这是文章列表页模板,moduleId="1"代表文章模型 #}
<div>
    {# 使用 archiveList 获取分页文档列表 #}
    {% archiveList archives with type="page" moduleId="1" limit="10" order="id desc" %}
        {% for item in archives %}
        <div class="article-item">
            <a href="{{item.Link}}">
                <h3>{{item.Title}}</h3>
                <p>{{item.Description}}</p>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </a>
            {% if item.Thumb %}
            <a href="{{item.Link}}">
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
            </a>
            {% endif %}
        </div>
        {% empty %}
        <p>当前分类下暂无内容。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 使用 pagination 渲染分页导航 #}
    <div class="pagination-nav">
        {% pagination pages with show="5" %}
            {# 显示总页数和当前页信息 #}
            <span class="page-info">共 {{pages.TotalItems}} 条,{{pages.TotalPages}} 页,当前第 {{pages.CurrentPage}} 页</span>

            {# 首页链接 #}
            <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>
        {% endpagination %}
    </div>
</div>

By the above code, you can not only clearly display each page of the document, but also provide the user with complete page navigation.This pagination strategy not only improves the organization of website content, but also optimizes the process of users obtaining information, having a positive impact on the website's SEO performance and user retention.A reasonable pagination setting can allow search engines to better crawl and index your content, avoiding the problem of slow page loading caused by loading too much content at once.

Frequently Asked Questions (FAQ)

  1. Ask: Why did I setlimitParameters, but the pagination navigation is not displayed on the page?Answer: This is because to implement a complete web pagination effect, in addition toarchiveListin the labellimitsetting the number of items displayed per page, it is more critical thattypeThe parameter must be set to"page", that istype="page"IftypeThe parameter is kept at default"list"or not set,limitIt will only limit the total number of items displayed, without enabling pagination functionality, thereforepaginationThe tags will not generate navigation links. Be sure to check.archiveListintypeParameter settings.

  2. Question: I want to display a 'Latest Articles' block on the page, showing only the most recent 5 articles without pagination, how should I set it up?archiveList?Answer: In this non-paginated static list scenario, you do not need to settype="page". You just need to specifyarchiveListUsed in tagslimitthe number of items to display, for example{% archiveList archives with limit="5" order="id desc" %}If you want to skip the first 2 articles and display 5 articles starting from the third, you can set it tolimit="2,5"Thus,archiveListit will directly retrieve and display the specific number of documents you need.

  3. Ask: My website has a lot of content, and every time I navigate through pagination, it shows ten or more page number links, which looks unattractive. What methods can be used to optimize it?Of course you can. You can adjustpaginationlabel'sshowthe parameters to control the number of pages displayed. For example, if{% pagination pages with show="5" %}is modified to{% pagination pages with show="3" %}you set it, the pagination navigation will only display 3 page links around the current page, such as... 2 [3] 4 ...This will make the pagination navigation look simpler and more professional, enhancing the user experience.

Related articles

How to implement sorting of the document list by views or publication time using the `archiveList` tag?

As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its flexibility and the efficiency of content presentation.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture in the Go language and a rich set of features.Today, let's delve deeply into a function that is extremely commonly used in content operation: how to use the `archiveList` tag to sort the document list by views or publication time.Content sorting seems simple, but it actually contains profound operational strategies.

2025-11-06

How to use the `archiveList` tag to get documents with specific recommended attributes (such as "Top Stories" or "Slideshow")?

As an experienced website operations expert, I am well aware of the core value of a content management system (CMS) in terms of its flexibility and content scheduling capabilities.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and rich features, providing strong support for content operations.Today, let's delve into a very practical scenario in content operation: how to accurately obtain and display documents with specific recommendation attributes using the `archiveList` tag, such as the website's 'headlines' news or important content for the 'slideshow' carousel.

2025-11-06

How to exclude documents of a specific category in `archiveList` to display accurate content?

As an experienced website operations expert, I am well aware of the importance of accurate content display for user experience and website operation efficiency.In a content management system, we often encounter the need to exclude certain specific categories of documents when generating article lists, in order to ensure the relevance and focus of the content.AnQiCMS (AnQiCMS) is an efficient and flexible content management tool that provides us with a very convenient solution.

2025-11-06

How to filter and display documents based on multiple category IDs for the `archiveList` tag?

As an experienced website operations expert, I fully understand that the flexibility of a content management system is crucial for efficient operations.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template tag system.Today, let's delve deeply into a very practical feature: how to use the `archiveList` tag to filter and display documents based on multiple category IDs, thereby creating more targeted and attractive content modules.

2025-11-06

How to use the `archiveList` tag to perform keyword search (using `q` parameter) to filter documents on the frontend page?

## Unlock AnQiCMS: Use the `archiveList` tag to implement keyword search and content filtering on the front-end page As an experienced website operations expert, I am well aware of the importance of an efficient and flexible content management system for enterprises.AnQiCMS, this system developed based on the Go language, with its excellent performance and rich features, is becoming the preferred choice for an increasing number of small and medium-sized enterprises and content operation teams.In today's era of information explosion, whether users can quickly find the content they need is directly related to the user experience and conversion rate of the website.

2025-11-06

How to retrieve related content of the current document using the `archiveList` tag's `type="related"` mode?

As an experienced website operations expert, I am very happy to delve deeply into the `archiveList` tag in AnQiCMS with the `type="related"` mode, which plays a crucial role in content operations and can effectively improve user experience and the website's SEO performance. --- ## In-depth Analysis of AnQiCMS's `archiveList` Tag: How to intelligently retrieve related content and enhance user experience In such an efficient and customizable content management system as AnQiCMS

2025-11-06

How to call the document data of different sites (`siteId`) through the `archiveList` tag?

As an experienced website operations expert, I fully understand the challenges you may encounter when managing multi-site content.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful multi-site management capabilities.Today, let's delve into how to use the `archiveList` tag and its core parameter `siteId` to easily implement cross-site document data calls.

2025-11-06

How to get the thumbnail, description, and publish time of the document in the `archiveList` loop?

As an experienced website operations expert, I know that how to efficiently and flexibly display content in a content management system is one of the key factors for the success of a website.AnQiCMS (AnQi CMS) relies on its powerful template engine and simple tag design, making content display extremely convenient.Today, let's delve into a very practical scenario: how to elegantly obtain and display the thumbnail, description, and publication time of documents in the `archiveList` loop.

2025-11-06