It is crucial to provide clear and attractive summaries for articles on the website in content management.This not only helps search engines better understand the content of the page, improve inclusion and ranking, but also quickly captures the attention of visitors on list pages, search result pages, or social sharing, guiding them to click and read the full content.AnQiCMS (AnQiCMS) provides various flexible ways to manage and access this content, including efficiently extracting and displaying article summaries (descriptionField`) is a common requirement in our daily operations.
AnQiCMS provides a set of intuitive and powerful API interfaces, making it very convenient to retrieve various data from the backend. We mainly use it for extracting article lists and their summaries.archive/listThis interface. The original intention of this interface design is to facilitate developers and operations personnel to obtain data of multiple articles, and the article summary field (description) Contains in the returned article object.
Efficient usearchive/listInterface extract summary
To get the article summary from the document list,archive/listThe interface is your preference. It is simple and direct in its calling method, throughGETthe method to send requests, and you can attach some parameters in the request to filter and control the returned data.
Firstly, you need to know the domain address of your AnQiCMS site. The general format of the API call address is:{域名地址}/api/archive/list. For example, if your website domain ishttps://en.anqicms.comThen, the interface address is:https://en.anqicms.com/api/archive/list.
When initiating a request, there are several key parameters to pay attention to that can help you accurately obtain the list of articles you need:
moduleId: This is a very important parameter, it specifies the document model you want to retrieve. For example, the ID of the conventional article model is usually1. If you want to get the product list or other custom model article summaries, you need to fill in the corresponding information according to the actual situationmoduleId.categoryId: If you want to get the article summary of a specific category, you can use this parameter. You can enter a single category ID, or separate multiple category IDs with commas.typeThis parameter controls the return mode of the list. When you need to display pagination, you should settypeis set topage. In this way, the interface will return the total number of articles at the same timetotalfield), convenient for you to build pagination navigation. If you just want to get a specified number of articles, the defaultlisttype is enough.limit: Used to specify the number of articles returned. For example,limit=10Indicates fetching 10 articles. It also defines the number of articles per page when pagination is needed. It even supportsoffset,limitpatterns such aslimit=2,10Represents starting from the second item and retrieving 10 items.page: Only whentypeis set topageis valid, used to specify which page of content you want to retrieve.
For example, if you want to get the summary of the latest 5 articles under the category with ID 10 of the article model, you can construct your API request in this way:
GET {域名地址}/api/archive/list?moduleId=1&categoryId=10&type=list&limit=5&order=created_time desc
After you send the request, if everything goes well, the interface will return a JSON-formatted data. In this JSON response,dataThe field is an array, each element of which represents a specific article information. The article summary we need is stored in each article object'sdescriptionin the field.
Return data example snippet (simplified):
{
"code": 0,
"data": [
{
"id": 1,
"title": "关于AnqiCMS",
"description": "安企内容管理系统(AnqiCMS),是一款使用 GoLang 开发的企业站内容管理系统,它部署简单,软件安全,界面优雅,小巧,执行速度飞快,使用 AnqiCMS 搭建的网站可以防止众多安全问题发生。",
// ... 其他文章信息
},
{
"id": 2,
"title": "AnqiCMS使用帮助",
"description": "anqicms常见问题汇总",
// ... 其他文章信息
}
],
"msg": "",
"total": 2
}
Once we obtain these data through an HTTP request, the subsequent processing is relatively simple. Whether it is to render data to an HTML template using backend languages (such as PHP, Python), or to parse JSON responses in front-end frameworks (such as Vue, React), it can be easily traverseddataArray, extract the content of each article'stitleanddescriptionfield and display it on the page.
Advanced application scenarios and practical suggestions
In practice, you may encounter some more complex requirements or need to consider performance optimization.
Obtaining a specific article abstractIf your scenario is to know the ID or alias of an article already
url_token),and only need to get the detailed information of this article (including the introduction), thenarchive/detailThe interface will be more direct. Just pass the article'sidorfilename(i.e.),url_token),can obtain all the data of the article, includingdescriptionfield. But if your purpose is to get a list,archive/listit is still a more efficient choice.front-end display optimizationWhen rendering the article list on the front-end page, you can use this obtained summary data to present it elegantly on the article list page, search results page, or related article recommendation module.For example, limiting the introduction to a certain number of characters, or adding a "Read More" link at the end of the introduction, can maintain the page's cleanliness and user experience.
Performance optimizationWhen the number of articles on the website is large, how should it be used rationally
limitandpageIt is crucial to paginate parameters. Avoid fetching all article data at once, as this can significantly reduce server pressure and data transfer time, improving website loading speed.At the same time, caching the data obtained on the client side can also reduce duplicate requests and further optimize the user experience.
By flexibly using the AnQiCMS providedarchive/listInterface, we can easily achieve efficient extraction and display of article summaries, greatly enhancing the flexibility of website content management and user experience.This not only makes your website content more attractive, but also provides users with better navigation and information preview.
Frequently Asked Questions (FAQ)
1. If thedescriptionfield is empty or the content is too short, how should I handle it?
WhendescriptionWhen a field is missing or insufficient in content, in order to ensure the display effect, you can set a backup logic on the front-end or back-end. A common practice is to take an example from the article'scontentField extracts the first few words as a substitute for the introduction. AnQiCMS'sarchive/listThe interface does not automatically截取 for you, therefore this needs to be judged and processed at the code level after you receive the data.If the article content is not suitable for direct extraction, you can display a general prompt, such as 'No introduction available'.
2. How to avoid performance issues when getting a large list of articles?
It is most critical to make reasonable use to avoid performance issuesarchive/listinterface'slimitandpageParameter.
limitCan limit the number of articles returned in a single request, it is recommended to set a reasonable value according to the page layout and user experience (for example, 10-20 articles per page).pagecooperatetype=pageThe parameter is used to enable pagination loading, only the data required for the current page is requested.In addition, you can also consider implementing lazy loading (Infinite Scroll) or infinite scrolling functionality on the front end, which loads the next page of content when the user scrolls to the bottom of the page, thus improving the user experience.
3.archive/listDoes the interface support retrieving the introduction of other content types (such as products, downloads)?
Yes,archive/listThe interface is generic. As long as you specify `