How to accurately filter out articles under specific categories when managing and displaying a large amount of content in AnQi CMS is a key factor in improving the organization of website content and user experience.The Auto CMS provides a powerful and flexible interface, allowing us to easily achieve this goal.This article will introduce in detail how to display specific category articles through the document list interface of the security CMS.
Master the document list interface: the core of content filtering
To filter articles under a specific category, we need to utilize the security CMS provided by/api/archive/listThe interface. This interface is the core to retrieve the document list of the website, which allows you to precisely control the returned article set through various parameters.
The calling method of the interface isGETThis means you can pass filter conditions via URL parameters. Among them,categoryIdthe parameter is the key to filter articles by category.
UnderstandingcategoryIdParameters
categoryIdParameter allows you to specify one or more category IDs, the interface will return articles belonging to these categories.
- Filter by single category:If you only want to display articles under a specific category, you can directly pass the category ID. For example, if you want to get the articles with ID of
10The classification of articles, the request parameters can includecategoryId=10. - Multi-classification filtering: If you want to display articles under multiple classifications at the same time,
categoryIdThe parameter also supports commas,Pass multiple category IDs in the form of separation. For example, to get articles under ID10/12and15, you can setcategoryId=10,12,15.
to build your filtering request
ExceptcategoryIdIn practical applications, it is usually necessary to coordinate other parameters to build a complete request to ensure that you obtain the content you truly need.
moduleId(Model ID):Documents usually belong to a specific model (such as article model, product model, etc.). To filter more accurately, it is recommended that you also specifymoduleIdFor example,moduleId=1represents obtaining documents under the article model.type(List type)When you need to get a paginated list and display the total number,typesetpage. If you just want to list a specified number of documents,typeyou can omit it or set it tolist.childAn item contains sub-items: A category may contain multiple sub-items. If you want to display not only the articles of the current category but also the articles of all its sub-items,childparameter settingstrue. By default, the AnQi CMS usually includes subcategories, but it can be explicitly specified.child=falseYou can only get the articles directly under the current category, without including the content of its subcategories.limitandpage(Pagination control)To control the number of articles displayed per page and to retrieve the content of a specific page number, you can uselimitandpageparameters. For example,limit=10&page=1to get the first 10 articles.
a complete request examplemight look something like this:
{域名地址}/api/archive/list?moduleId=1&categoryId=10,12,15&type=page&limit=10&page=1&child=true
This request means: Get the article model (moduleId=1) under, the category ID is (10/12and15(including subcategories) article, displayed in a paginated form, 10 items per page, get the content of the first page.
Parse return result
After you send a request, the CMS will return a JSON formatted response. A successful response usually includescode: 0and adatafields, wheredataThe field is an array containing articles that meet the filtering criteria. Each article object will containid/title/description/category_idetc. detailed information, which you can use to display on the front end.
Passed the data verificationcategory_idField, you can verify whether the interface has filtered according to your expectations. In addition, iftypeparameter settingspage, there will also be atotalField, tells you the total number of documents that meet the conditions, which is very helpful for implementing pagination.
Summary
By using flexibilityarchive/listInterface and itscategoryIdParameters, you can accurately control the display of content on the Anqi CMS website.This interface can provide solid support for building classification lists, specific topic pages, or even more complex filtering functions.moduleId/typeandchildEnglish parameters, you can create functional and user-friendly content display pages.
Common Questions (FAQ)
1. How to get the categoriescategoryId?
You can call/api/category/listInterface to get the list of all categories, each category will containidfield, which is what you needcategoryId. You can also get it through/api/category/detailinterface, by passing the category name (catnameorfilename)to get detailed information of a single category, which also includesid.
2. I want to display articles under a certain category but not include the articles of the subcategory, what should I do?
When calling/api/archive/listwhen calling the interface, thechildparameter settingsfalseIt is. For example:categoryId=10&child=falseEnglish interface will only return articles directly under ID10articles, and will not include articles under its subcategories.
3. How can I exclude certain category articles instead of only displaying specific category articles?
Anqi CMS's/api/archive/listThe interface also provides aexcludeCategoryIdParameter. You can pass the category IDs to be excluded in comma-separated form to this parameter.,For example,excludeCategoryId=10,12It will return all articles but exclude those belonging to the category with ID10and12.