How to precisely control the number of documents returned and the starting offset of AnQiCMS document list (advanced usage of `limit` parameter)?

Calendar 👁️ 67

When building and managing website content, AnQiCMS provides a series of flexible API interfaces to help us accurately obtain and display data. Among them,archive/listThe interface is the core to obtain the document list, and itslimitparameters, in terms of controlling the number of returned items and the starting offset, demonstrate its powerful fine-grained control ability. Understand and make good use oflimitAdvanced usage of the parameter, which can make our website content display more flexible and efficient.

limitBasic usage of the parameter: control the number of returned items.

limitThe most direct use of the parameter is to specify how many records you want to retrieve from the document list. For example, when you want to display the latest 5 articles in a certain block of a website, or 10 popular recommendations in a certain category,limitParameters can be put to good use.

You can use it like this:

/api/archive/list?moduleId=1&limit=5

This request will return the article model (moduleId=1) the latest 5 articles. In this mode,limitfollowed by a number, AnQiCMS will get the query results frombeginningStart, return the specified number of documents. This is very practical in many scenarios that require displaying a fixed amount of content, such as "Latest News", "Great Reviews", etc.

limitAdvanced usage of parameters: precise control of the starting offset and return quantity

limitThe real strength of the parameter lies in the advanced usage it provides, allowing us to not only control the number of returns but also to specify exactly from which record to start. When you need to skip the first few records, or not use the traditional pagination mode (type="page"In the case of, when extracting a part of the data from the middle of the result set, this usage is particularly important.

Advanced usage by passing two values separated by a comma string:limit="OFFSET,COUNT".

  • OFFSET (offset amount): This is the number of records you want to skip. Please note that it representshow many records to skip rather than starting from which record. For example,OFFSET=0Starting from the first record,OFFSET=2Then it means skipping the first two records, starting from the third to retrieve.
  • COUNT (quantity): This is the number of records you want to return.

Let's look at a specific example:

/api/archive/list?moduleId=1&limit=2,5&order=created_time desc

The meaning of this request is: from the article model (moduleId=1In this case, skip the first 2 records (sorted in descending order by publish time), and then return the next 5 records starting from the 3rd record.

This flexible control method brings great convenience to content display:

  • Skip specific contentIf your website has featured articles or recommended content, you may want to skip these entries that have already been specially displayed in the regular list. By setting an appropriateOFFSETValue, you can easily achieve this. For example, if the top of the homepage has already displayed 1 headline article, and you want other areas to display the remaining latest articles, you can uselimit=1,N(N is the number of remaining articles you want to get).
  • Build a complex layoutIn complex page layouts, it may be necessary to display different parts of the same document list in different locations.For example, a page is divided into a left-hand hot recommendation and a right-hand ordinary list. The hot recommendations take the first 3, and the right-hand ordinary list takes the 4th to the 10th.limit='0,3'andlimit='3,7'(This means taking 3 articles starting from the first and 7 articles starting from the fourth), which can be very elegantly implemented.

limitwithtypeparameter collaboration

Inarchive/listin the interface,limitthe behavior of the parameter will also be affected bytypethe parameter's influence. By default,typehas a value oflistIn this case,limit="OFFSET,COUNT"the pattern can be used directly.

However, when we settype="page"enable traditional pagination mode,limitthe parameter will be the number of items displayed per page, andpageThe parameter is used to control the page number (i.e., it implicitly controls the offset). In this case, you do not need to useOFFSET,COUNTthe format, butlimitspecify the number of items per page separately,pageand specify the current page number.

For example, if you need to get the second page of the article list, with 10 items per page, your request would be:

/api/archive/list?moduleId=1&type=page&page=2&limit=10&order=created_time desc

Please pay close attention to this distinction:limit="OFFSET,COUNT"Primarily used fortype="list"ortype="related"In scenarios where pagination does not apply, or when you need to highly customize the starting position and quantity rather than in the traditional sense of 'pages'.

To ensure that each request results in a stable and consistent outcome, especially when usingOFFSET,COUNTpatterns, it is strongly recommended to use parameters to explicitly specify the sorting method, for exampleorderfor exampleorder='created_time desc'Otherwise, in cases of large data volume or frequent updates, the default sorting may cause the 'Nth record' you obtain to not always be the one you expect.

Summary

AnQiCMS'limitThe parameter is not just a simple quantity controller, through itsOFFSET,COUNTAdvanced usage, it has become a powerful data extraction tool.In order to achieve specific content display logic, optimize page loading, or build a more refined website content layout, mastering this method will greatly enhance your efficiency and flexibility in AnQiCMS content operation and development.


Frequently Asked Questions (FAQ)

Q1:limit='5'andlimit='0,5'What is the difference?A1: In terms of function,limit='5'andlimit='0,5'The effect is completely the same. They all indicate starting from the first record in the result set (i.e., skipping 0 records) and returning the next 5 records.limit='5'It is a shorthand form, which can be used when you only need to specify the number of returns without explicitly specifying the offset, making it a more concise expression.

Q2: When usinglimit='OFFSET,COUNT'If myOFFSETWhat will happen if the value is too large and exceeds the total number of documents?A2: If you specifyOFFSETThe value is greater than or equal to the total number of documents under the current query condition, the API will return an empty document list (dataThe field is an empty array), at the same timecodeIt remains 0, indicating that the request was successful but no documents meeting the criteria were found.

Q3:limitCan the parameter be used with other filtering conditions (such ascategoryId/flag)?A3: Of course, you can.limitThe parameter takes effect after all other filtering and sorting conditions are processed. This means that AnQiCMS will first sort according tomoduleId/categoryId/flag/qand then filter out the document set that meets the conditions according toorderThe parameter sorts these documents and then based onlimitthe parameter to return the documents with specified quantity and offset.

Related articles

What is the main difference between the `type="page"` and `type="list"` modes in the AnQiCMS document list interface?

When you are using AnQiCMS to build a website and need to retrieve document content from the backend, you will often encounter the document list interface (/api/archive/list).This interface provides a very important `type` parameter, which determines how you will obtain and process the document list data.A deep understanding of the core differences between the `type="page"` and `type="list"` modes is crucial for improving website performance, optimizing user experience, and developing more flexible features.###

2025-11-09

How to get the latest document list of the specified model (`moduleId`) through AnQiCMS?

In website content management, we often need to dynamically display the latest updates of a certain type of content, such as news articles, product releases, or blog updates.For websites built using AnQiCMS, leveraging its powerful API interface to obtain the latest document list under a specified model is a very basic and practical operation.This can not only help developers build dynamic pages quickly, but also provide users with timely updated information, optimizing the user experience of the website.To implement this feature, we mainly use the AnQiCMS provided

2025-11-09

How to dynamically build a frontend filtering UI based on the response of `archiveFilters`, such as dropdown menus or checkboxes?

In today's increasingly rich content of websites, how to allow users to quickly find the information they are interested in is a crucial operational issue.AnQiCMS provides powerful content management capabilities, and its API interface provides a solid foundation for front-end developers to build flexible and varied interactive interfaces.Today, let's delve into how to use the response data from the `archiveFilters` interface to dynamically build front-end filtering UI, such as common dropdown menus or checkboxes.The value of dynamic filtering interface Imagine that

2025-11-09

Does the `archiveFilters` interface require user login authorization to access?

In the daily application of Anqi CMS, the `archiveFilters` interface is an important tool for dynamically displaying filter conditions on the front-end page. It allows the website to generate various filter options based on the field configuration of the article model, such as "city", "education", and so on.It is crucial for building a user-friendly content browsing experience, where users can quickly locate content of interest through these filtering conditions.However, many developers may have a question when integrating: does this interface require user login authorization to access?To answer this question

2025-11-09

How to implement descending order by publish time, view count, or update time in the AnQiCMS document list?

In website operation, how to efficiently present content lists so that users can quickly find the information they are most interested in or most valuable is an important issue.AnQiCMS provides a flexible document list feature, allowing us to easily implement content list sorting in descending order based on multiple conditions, such as publication time, page views, or update time.This not only optimizes the user experience, but also helps to improve the visibility and interaction of the content.

2025-11-09

How to filter the AnQiCMS document list to display articles under a specific category (`categoryId`)?

How to accurately filter out articles under specific categories when managing and displaying a large amount of content in Anqi CMS is a key link to improve the organization of website content and user experience.Strong and flexible interfaces are provided by AnQi CMS, allowing us to easily achieve this goal.This article will provide a detailed introduction on how to use the document list interface of Anqi CMS to only display specific categorized articles that you hope to see.### Master the document list interface: the core of content filtering To filter articles under specific categories, we need to use the `/api/archive/list` interface provided by AnQi CMS

2025-11-09

Does the AnQiCMS document list interface support excluding multiple categories of documents at the same time (`excludeCategoryId` usage)?

In website operation, we often need to flexibly display content, such as displaying the latest articles on a page, but not including content under certain specific categories, such as announcements or internal news.AnQiCMS as a powerful content management system, provides a rich set of API interfaces to meet these complex display requirements.Today, let's delve into a very practical parameter of the `archive/list` interface: `excludeCategoryId`, especially how it supports excluding multiple categories of documents.###

2025-11-09

How to get the document list with 'Headline' or 'Slide' recommended attributes (`flag`) in AnQiCMS?

In AnQiCMS (AnQiCMS), content managers often need to flexibly display important content on the website, such as setting specific articles as 'headline' or 'slideshow' to attract users' attention.The AnQi CMS provides a very practical feature, that is, marking documents through the 'recommended attribute' (flag).If you want to get the list of documents marked specially, the AnQiCMS API interface can help you achieve it easily.

2025-11-09