In AnQiCMS (AnQiCMS), content operators often need to flexibly display important content on the website, such as setting specific articles as 'headline' or 'slideshow' to attract users' attention. AnQiCMS provides a very practical feature for this, which is to use 'recommended attributes' (flag) to mark the document. If you want to get the list of documents marked specially, you can easily achieve this with the AnQiCMS API interface.
Understanding the "recommended attributes" of the document (flag)
In Anqi CMS, each document may have one or more recommended attributes, which are marked with single letters for easy classification and display on the website. For example:
- HeadlineUse
hA tag, usually used in the most prominent position on the homepage to display the most important content. - SlideUse
fLabel, commonly used in carousel or slide show area, attracting users with images and titles. - Other common properties include: recommended
c, special recommendationa, scrolls, boldh(Note, herehIt can represent both headline and bold, but it is usually agreed upon in content management), imagep, jumpjetc.
A document can have multiple properties, such as both 'headline' and 'slide', so itsflagvalue may behf. Understanding these tags is the basis for obtaining a specific list of documents.
Usearchive/listRetrieve document list from the interface
To retrieve a document list with specific recommendation attributes, we need to utilize the Anqi CMS providedarchive/listInterface. This is a very powerful interface that allows you to filter documents based on multiple conditions.
Basic interface information
- API call address:
{域名地址}/api/archive/list - Call method:
GET
Core parameters:flag
Inarchive/listAmong the many request parameters of the interface,flagthe parameters are the key to achieving our goal. It allows you to specify the recommended attributes to match.
How to useflagparameters:
- Retrieve documents with a single recommendation attributeTo retrieve all documents marked as 'Headline', just
flagthe parameter toh, that isflag="h". Similarly, to retrieve 'Slide' documents isflag="f". - Retrieve a document with one of multiple recommended attributesIf you want to retrieve thoseeither "Headline" or "Slideshow"documents, you can use multiple
flagvalues separated by commas,Separate. For example, to get documents such as 'Headline' or 'Slide', the parameter is set toflag="h,f". At this point, as long as theflagattribute containshorfany one of them, it will be retrieved.
Combine other practical parameters
exceptflagIn addition, you usually need to work with other parameters to accurately control the returned results:
moduleId: It is strongly recommended to specify the model ID of the document you belong to, for example, the article model ID is usually1This can prevent the retrieval of documents from other models (such as product models), ensuring data consistency. For example,moduleId=1.limit: Controls the number of returned documents. If you only need to display a few, you can setlimit=5. If you need pagination, you can also uselimit="2,10"to specify starting from the 2nd item and getting 10 items.typeWhen you need to get the total count and display it with pagination, you can settype="page". If you just need to get a list, the defaultlisttype is enough.order: You can set the sorting method as needed, for exampleorder="created_time desc"This means sorting in reverse order by publication timeorder="views desc"This means sorting in reverse order by views
Actual operation example
To better understand, let's look at some specific API request examples. Assuming your website domain iswww.yourdomain.com, the article model ID is1.
1. Get all the latest articles marked as 'Headline', up to 5 articles:
{域名地址}/api/archive/list?moduleId=1&flag=h&limit=5&order=created_time desc
Replace{域名地址}Withhttps://www.yourdomain.com, the complete request would look like:https://www.yourdomain.com/api/archive/list?moduleId=1&flag=h&limit=5&order=created_time desc
2. Get all popular articles marked as 'Slide', without limiting the number and supporting pagination:
{域名地址}/api/archive/list?moduleId=1&flag=f&type=page&order=views desc&page=1&limit=10
This will get all articles under the article model,flagincludingfThe document properties, sorted by view count in descending order, 10 items per page, get the first page.
3. Get all documents marked as "Headline" or "Slideshow" and display 3 randomly.
{域名地址}/api/archive/list?moduleId=1&flag=h,f&limit=3&order=rand()
(Please note,rand()Not all databases or APIs support it, this is for demonstration purposes, and in practice, it may require backend support or random selection on the frontend)
Interpret the returned data
After you make a request, the interface will return a JSON-formatted data. A successful response will includecode: 0and adataAn array where each element is a document object. You can findtitle/description/thumb(thumbnail),link(document link) and the ones we are interested inflagField information. Through this data, you can display selected document content on your website.
By following these steps, you can accurately obtain a list of documents with specific recommendation properties in AnQiCMS, providing strong support for your website content operation.
Frequently Asked Questions (FAQ)
Q1: How should I set the API request to retrieve documents that have both the 'Headline' and 'Slide' properties?A1: Anqi CMS'flagThe parameter is designed to match the "or" relationship by separating with commas (i.e., including any specified attribute). If a document has bothhandfproperties (such as itsflagfield value ishf), then you pass throughflag="h"orflag="f"evenflag="h,f"Can get it. There is no direct "AND" logical filtering method at the API level, but usually a document marked as "headline" and "slide", itsflagThe field will include itselfhandf,flag="h,f"It can meet most 'or' relationship needs.
Q2:moduleIdWhy is the parameter so important, what if I don't specify?A2:moduleIdUsed to specify the model to which the document belongs, such as articles, products, images, etc. The structure of documents under each model may vary, and the content may be very different. If not specifiedmoduleIdAn interface may search all models, leading to the return of irrelevant data or a data structure that does not meet your expectations, which may affect the accuracy of front-end display. Specify explicitly.moduleIdEnsure that you obtain the content under the target model, improving data accuracy and interface efficiency.
Q3: How to display the content of the document list on my website after obtaining it?A3: After obtaining the JSON data of the document list, you need to parse these data according to your front-end technology stack (such as HTML, CSS, JavaScript, or Vue/React frameworks), and you will usually iterate over them.dataAn array, dynamically generates HTML elements for each document, displaying its title, thumbnail, introduction, and links to the document detail page. You can use the returned data intitle/thumb/descriptionandlinkThe field is formatted and rendered to form a beautiful 'headline' or 'slideshow' area on the website.