In content management, it is crucial to provide clear and engaging summaries for articles on the website.This not only helps search engines better understand the page content, improve inclusion and ranking, but also quickly catches the attention of visitors on list pages, search result pages, or social sharing, guiding them to click and read the full content.descriptionThe field `)` 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. For extracting article lists and their summaries, we mainly usearchive/listThis interface. The original intention of this interface design is to facilitate developers and operators to obtain data of multiple articles, and the article summary field (descriptionEnglish includes its return in each article object.
Efficient utilizationarchive/listInterface extract summary
To get the article summary from the document list,archive/listThe interface is your preferred choice. It is simple and direct to call, throughGETSend requests using the method and you can add some parameters 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 ishttps://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 required articles:
moduleId: This is a very important parameter, it specifies the document model you want to retrieve. For example, the ID of the general article model is usually1If you want to get the product list or other custom model's article summary, you need to fill in the corresponding information according to the actual situation.moduleId.categoryId: If you want to get the article abstracts under a specific category, you can use this parameter. You can enter a single category ID, or enter multiple category IDs separated by commas.type: This parameter controls the return mode of the list. When you need to display pagination, you should settypesetpage. The interface will return the total number of articles at the same time,totalField), which is 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=10Represents getting 10 articles. It also defines the number of articles per page when pagination is needed. It even supportsoffset,limitpatterns likelimit=2,10Represents starting from the 2nd data item, fetching 10 data items.page: Only whentypesetpageis 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 like this:
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 data in JSON format. In this JSON response,dataThe field is an array, where each element represents a specific article information. And the article summaries we need are stored in each article object.descriptionfield in.
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 have obtained this data through an HTTP request, the subsequent processing is relatively simple. Whether it is to render the data into an HTML template using backend languages (such as PHP, Python), or to parse the JSON response in a frontend framework (such as Vue, React), it can be easily traverseddataArray, extract each article'stitleanddescriptionfield and display it on the page.
Advanced application scenarios and practice suggestions
In practical applications, you may encounter some more complex requirements, or need to consider performance optimization.
Obtaining a specific article abstract: If your scenario is that you already know the ID or URL alias of an article (
url_token),and only need to obtain the detailed information of this article (including the introduction), thenarchive/detailthe interface will be more direct. Just pass in the article'sidorfilename(i.e.,)url_token),can get all the data of the article, includingdescriptionfield. But if your goal is to get a list,archive/listis still a more efficient choice.optimization of front-end displayEnglish: In the frontend page rendering of the article list, you can use the obtained summary data to elegantly present it 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 cleanliness of the page and the user experience.
Performance optimization: When the number of articles on the website is large, make reasonable use of
limitandpageIt is crucial to paginate the parameters.Avoid fetching all article data at once, which can significantly reduce server pressure and data transfer time, improving the website loading speed.Also, caching the data obtained on the client side can reduce redundant requests and further optimize the user experience.
By flexibly using the features provided by AnQiCMSarchive/listWe can easily extract and display the article abstract efficiently, greatly enhancing the flexibility of website content management and the user experience.This not only makes your website content more attractive, but also provides users with better navigation and information preview.
Common Questions (FAQ)
1. If the articlesdescriptionField is empty or content is too short, what should I do?
WhendescriptionField missing or content insufficient, 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 extract from the article'scontentField extracting the first few words as a substitute for the introduction. AnQiCMS'sarchive/listThe interface will not automatically截取 for you, therefore this needs to be judged and processed at the code level after you receive the data.If the content of the article is also not suitable for direct extraction, a general prompt can be displayed, such as "No introduction available."
2. How to avoid performance issues when getting a large list of articles?
To avoid performance issues, the most crucial thing is to use it reasonablyarchive/listthe interface'slimitandpageParameter.
limitCan limit the number of articles returned per request, it is recommended to set a reasonable value based on page layout and user experience (for example, 10-20 articles per page).pagewithtype=pageParameter usage, can realize pagination loading, only request data for the current page.Moreover, you can also consider implementing lazy loading (Infinite Scroll) or infinite scrolling functionality on the frontend, which loads the next page of content only when the user scrolls to the bottom of the page, thereby enhancing the user experience.
3.archive/listIs the interface supported to obtain the summary of other content types (such as products, downloads)?
Yes,archive/listThe interface is universal. As long as you specify `