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

Calendar 👁️ 73

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 not only helps developers quickly build dynamic pages, but also provides users with timely updated information to optimize the website experience.

To implement this feature, we mainly use the AnQiCMS provided/api/archive/listThe document list interface. This interface is very flexible, and by combining different parameters, we can accurately filter, sort, and obtain the desired content.

Understandingarchive/listInterface

First, let's understand this core interface. Its call address is usually{域名地址}/api/archive/listAnd thenGETrequest is sent by the method. Here is{域名地址}Replace with your actual website domain, for examplehttps://en.anqicms.com/api/archive/list.

This interface has many parameters, but in order to getList of latest documents under the specified modelWe need to pay special attention to the following:

  1. moduleId(Model ID)This is a required parameter in the request. Each content model created in the AnQiCMS backend (such as "articles", "products", etc.) has a unique numeric ID.Specify throughmoduleIdWe tell the system which model's documents we want to retrieve.
  2. order(Sorting method)This is the key to achieving the "latest" effect. AnQiCMS supports sorting by multiple fields, including those related to time such ascreated_time(Publishing time) andupdated_time(Update time). To get the latest content, we will set it tocreated_time descorupdated_time descof whichdescmeans in descending order, that is, the latest in front.
  3. limit(Display number)This parameter is used to control how many of the latest documents you want to retrieve. For example, if you want to display the most recent 5 articles, you can setlimit=5If you need to retrieve a certain number of data from a certain record, you can also useoffset,limitformat, such aslimit=2,10It means to retrieve 10 data from the 3rd record.
  4. type(List type): By default,typeThe value islistIt will directly return the specified number of documents. If you need to display pagination (such as showing the total number of pages or total number of items), then you can usetypeis set topageat this time, you can usepageParameters can retrieve the content of a specified page. However, for simple "latest list" needs, keep the default.type=listJust do it.

Actual operation example

Assuming your "article" model'smoduleIdIs1,You now want to get the 5 latest articles released under this model. You can construct the API request in the following way:

GET {您的域名}/api/archive/list?moduleId=1&order=created_time desc&limit=5

After you send this GET request, AnQiCMS will return a JSON formatted data. In the case of success,codethe field will be0whiledataThe field will contain the document list you requested.

The data structure returned is roughly as follows:

{
  "code": 0,
  "data": [
    {
      "id": 101,
      "created_time": 1705000000, // 较新的发布时间
      "updated_time": 1705000050, // 较新的更新时间
      "title": "AnQiCMS新功能发布:AI智能写作模块上线!",
      "description": "详细介绍AnQiCMS最新推出的AI智能写作功能,帮助您高效创作内容。",
      "module_id": 1,
      "category_id": 5,
      "views": 120,
      "thumb": "https://yourdomain.com/uploads/images/ai-feature.webp",
      "link": "https://yourdomain.com/news/101.html",
      // ... 其他文档信息
    },
    {
      "id": 100,
      "created_time": 1704900000,
      "updated_time": 1704900030,
      "title": "AnQiCMS 3.0版本更新日志",
      "description": "回顾AnQiCMS 3.0版本的各项优化与改进,提升您的使用体验。",
      "module_id": 1,
      "category_id": 1,
      "views": 150,
      "thumb": "https://yourdomain.com/uploads/images/version-3.0.webp",
      "link": "https://yourdomain.com/news/100.html",
      // ... 其他文档信息
    }
    // ... 剩余3条最新文档
  ],
  "msg": ""
}

In the returneddataarray, each item is a document object. You can easily extract it fromtitle(Title),description(Summary),thumb(thumbnail),link(Document link) and present it on your website or application interface.created_timeandupdated_timeThe field is returned in the form of a Unix timestamp, you can convert it to a readable date format.

Practical Tips and **Practice**

  • clearmoduleId:In your AnQiCMS backend, go to the 'Content Model' management interface to view each model's ID. Make sure you are usingmoduleIdis correct.
  • Flexible applicationorderparameters:exceptcreated_time desc, and you can also tryupdated_time descGet the latest modified document orviews descGet the popular documents.
  • Moderate settinglimit:Reasonably set according to the page layout and content display requirementslimitAvoid making too many requests at once to prevent affecting loading speed.
  • Error handling mechanism:When integrating API calls in front-end or back-end code, be sure to check the returnedcodefield. Ifcodenot0means that the request failed, at this point you canmsgget the error reason through the field and take appropriate handling or prompting.

By the above method, you can easily use the AnQiCMS API to get the latest document list under any specified content model, injecting vitality into your website or application.


Frequently Asked Questions (FAQ)

Q1: How do I know my content model?moduleIdWhat is it?A1: You can find it in the AnQiCMS admin interface.moduleId. Usually in the 'System Settings' or 'Content Model' related menus, each model will display its corresponding ID.For example, when clicking on the edit page of a content model, the model ID is usually marked in the URL or next to the model name.You can also call by using/api/module/listThe interface retrieves the list of all content models, which includesidandtitlefield.

Q2: If I need to get the latest documents under a certain category (not the entire model), what should I do?A2: If you only want to retrieve the latest document in a specific category, you canarchive/listadd an extra parameter in the interfacecategoryIdand set its value to the ID of the target category. For example,GET {您的域名}/api/archive/list?moduleId=1&categoryId=10&order=created_time desc&limit=5It will retrieve the latest 5 articles with model ID 1 and category ID 10.You can find the corresponding category ID in the "Category Management" of the AnQiCMS backend.

Q3: How to ensure that my website can continuously obtain the latest content without causing problems due to too frequent API requests?A3: It is recommended to implement a caching mechanism on your server or frontend (depending on the actual situation) for the frequently accessed 'latest documents' list.For example, request the API to update data every 5-10 minutes, and then cache the data for user access, rather than directly requesting the API each time the page is loaded.This can significantly reduce the pressure on API requests and improve page loading speed.

Related articles

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 properly handle the error codes returned by the `archiveFilters` interface (such as -1, 1001, 1002)?

During the operation and development of the website, we often use various API interfaces provided by Anqi CMS to dynamically obtain and display content.Among them, the `archiveFilters` interface plays an important role, helping us to obtain the document filtering conditions, thus providing users with a more refined content browsing experience.However, correctly handling the error codes returned by any API is crucial to ensure the stable operation of the website and a smooth user experience.

2025-11-09

What would the `archiveFilters` interface return if a document model does not have filterable custom fields?

In Anqi CMS, the `archiveFilters` interface is a very practical feature that allows us to retrieve the filtering conditions of specific document models, thereby helping users to implement flexible content filtering on the front-end page.For example, on a product display page, we may need to filter products based on attributes such as 'color', 'size', or 'brand'. What if a document model is exactly configured without any filterable custom fields, what will the `archiveFilters` interface return?

2025-11-09

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 precisely control the number of documents returned and the starting offset of AnQiCMS document list (advanced usage of `limit` parameter)?

When building and managing website content, AnQiCMS provides a series of flexible API interfaces to help us accurately obtain and display data.Among them, the `archive/list` interface is the core for obtaining the document list, and its `limit` parameter demonstrates its powerful fine-grained control capabilities in terms of controlling the number of returned items and the starting offset.Understand and master the advanced usage of the `limit` parameter, which can make our website content display more flexible and efficient.### `limit` parameter basic usage

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