When you are using AnQiCMS to build a website and need to obtain document content from the backend, you will often come across the document list interface (/api/archive/list). This interface provides a very importanttypeParameter, it determines how you will obtain and process the document list data. In-depth understandingtype="page"andtype="list"The core difference between these two modes is crucial for improving website performance, optimizing user experience, and developing features more flexibly.
type=“list” mode: Efficiently retrieve small-scale data
type="list"The mode is the default behavior of the document list interface. Its design philosophy is toQuickly and lightweight to retrieve a fixed number of document contentsAnd without concerning the total scale of the data.When you only need to display a small amount of selected content in a specific block of a website, such as 'Latest Releases' on the homepage, 'Hot Recommendations' in the sidebar, or 'Related Articles' on the article detail page, this mode is very efficient.
In this mode, you can take advantage oflimitparameter to accurately control the number of returned documents, for examplelimit="5"It will return the latest 5 articles. It is worth mentioning that,limitIt also supports a usage of "offset", for example,limit="2,10"This means you want to skip the first two records and start retrieving the next 10 documents from the third record. This mechanism is very flexible in certain specific display scenarios.
However,type="list"The characteristics of the pattern also determine its limitations: it will not include the total number of documents in the returned data (totalfield), nor does it support keyword searches (qParameters and custom filtering such as advanced query features. This makes it unsuitable for scenarios that require pagination display or complex search filtering.
type=“page” Mode: A powerful tool for building complete pagination and search functions
Withtype="list"different,type="page"Mode designed forScenarios requiring complete pagination, search, and advanced filtering functionsIf you are building a blog list page, news archive page, or product showcase center, users need to be able to browse all content, perform pagination, and even search for information through keywords or specific attributes.type="page"Pattern is your preference.
When you are going totypeset"page"When, the interface will not only return the document list data of the current page, but also provide an extratotalField, clearly indicating the total number of documents that meet the query conditions.totalThe value is the key to constructing the front-end pagination navigation, allowing users to intuitively understand the overall scale of the content and easily jump to different pages.
In addition,type="page"The mode also unlocks multiple advanced features. You can work withpageparameters to specify which page of content to retrieve, and tolimitdefine how many documents to display per page. What's more powerful is,qParameters can be used in this mode for keyword search, helping users quickly locate documents containing specific words in the title; at the same time, if you have configured custom filter fields for the document model in the AnQiCMS background, you can also pass the URL query parameters in the form ofgender=男)来实现更细致的自定义筛选。
核心区别概览
In summary,type="page"andtype="list"的主要区别体现在以下几个方面:
- 数据返回:
type="list"仅返回指定数量的文档,不包含总数;type="page"Return the list of documents on the current page and providetotalTotal number of documents. - Pagination support:
type="list"Not supportedpageParameters for pagination;type="page"SupportpageandlimitParameters to implement full page navigation. - Advanced Query:
type="list"Does not support keyword search (q) and custom filtering;type="page"Fully supports these features, able to build more interactive list pages. - Applicable scenarios:
type="list"适用于快速获取小范围、固定数量的展示内容,如推荐位;type="page"适用于需要完整内容列表、分页浏览、搜索和筛选的归档页面。
In actual development, choose the appropriate one according to your content display requirementstypePattern, which enables you to make more efficient use of AnQiCMS data interfaces, avoid unnecessary data transmission, and thus enhance the website's loading speed and user experience.
Common Questions (FAQ)
Q1:Can I usetype="list"the pattern to get all the articles of the website?A1:It is not recommended to do so.type="list"The primary purpose of the pattern is to retrieve a small amount of data, it will not return the total number of articles, and fetching all articles at once may cause the request response to be slow due to the large amount of data, and even timeout. If you need to retrieve all articles and display them with pagination, please make sure to usetype="page"pattern.
Q2: intype="list"mode,limit="5,10"What does it mean?A2:limit="5,10"The English translation of 'auto' is 'English'.This is a "offset + quantity" retrieval method, which is very practical in some specific local content display scenarios.
Q3: Why am Itype="list"using modeqsearch with parameters, but it didn't work?A3:Keyword search(qParameters) and custom filtering function are fortype="page"mode designed.type="list"The pattern focuses on simple, fixed-number content retrieval, therefore it does not support these advanced query features. If you need to search or filter documents, please make sure totypeparameter settingspage.