How to accurately filter articles under specific categories in Anqi CMS, which is a key aspect for improving the organization of website content and user experience.Anqi CMS provides a powerful and flexible interface, 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 the specific category articles you hope to see.

Master the document list interface: the core of content filtering

To filter articles under specific categories, we need to make use of the Anqi CMS provided/api/archive/listThe interface. This interface is the core for obtaining the list of website documents, allowing you to precisely control the set of returned articles through various parameters.

The method of calling the interface isGETThis means you can pass filtering conditions through URL parameters. Where,categoryIdParameters are the key to implementing category-based article filtering.

UnderstandingcategoryIdParameter

categoryIdThe parameter allows you to specify one or more category IDs, and the interface will return articles belonging to these categories.

  • Single category filteringIf 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 ID of10articles under the category, the request parameters can includecategoryId=10.
  • multi-category filtering: If you want to display articles under multiple categories at the same time,categoryIdthe parameter also supports commas,Pass multiple category IDs in the form of separation. For example, to get the ID of10/12and15articles under the category, you can setcategoryId=10,12,15.

build your filter request

exceptcategoryIdIn practice, it is usually necessary to combine other parameters to construct a complete request to ensure that you get the content you really 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=1means to retrieve documents under the article model.
  • type(List type): When you need to get a paginated list and display the total count, it is usually thattypeis set topage. If you just want to list a specified number of documents,typeyou can omit or set it tolist.
  • child(Subcategory includes): A category may contain multiple subcategories. If you want to display not only the articles of the current category but also the articles of all its subcategories, you can setchildthe parameter totrue. By default, Anqi CMS usually includes subcategories, but it can be specified explicitlychild=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 content for specific page numbers, you can uselimitandpagethe parameters. For example,limit=10&page=1to get the first 10 articles of the page.

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

The meaning of this request is: to get the article modelmoduleId=1under, the category ID is10/12and15(including subcategories) articles displayed in a paginated manner, 10 per page, to get the content of the first page.

Parse the return result

After you send the request, AnQi CMS will return a JSON formatted response. A successful response will usually includecode: 0and adatafields, among whichdataA field is an array containing articles that meet the filtering criteria. Each article object will containid/title/description/category_idetc. information, you can display this information on the front end.

Check the returned data to verifycategory_idthe field, you can verify if the interface has been filtered according to your expectations. In addition, iftypethe parameter topage, the response will also include atotalField, tells you the total number of documents that meet the criteria, which is very helpful for implementing pagination.

Summary

By flexible applicationarchive/listThe interface and itscategoryIdParameters, you can accurately control the display of content on the AnQi CMS website.This interface can provide solid support for building category lists, special topic pages, and even more complex filtering functions. CombinedmoduleId/typeandchildWith parameters, you can create a feature-rich and user-friendly content display page.


Frequently Asked Questions (FAQ)

1. How to get the categories ofcategoryId?

You can call/api/category/listInterface to get the list of all categories, where each category will containidfields, this is what you needcategoryId. You can also get/api/category/detailinterface, passing the category name (catnameorfilenameTo get the details of a single category, which also includesid.

2. How can I display articles under a category without including articles from subcategories?

When calling/api/archive/listparameter to:childthe parameter tofalse.categoryId=10&child=false. The API will only return articles directly belonging to the ID of10category, and will not include articles from its subcategories.

3. How can I exclude certain categories of articles instead of just displaying specific categories of articles?

Of Security CMS/api/archive/listThe interface also provides aexcludeCategoryIdParameter. You can pass the category IDs to be excluded in comma-separated format,to this parameter. For example,excludeCategoryId=10,12It will return all articles but exclude those belonging to category10and12ID articles.