When using AnQi CMS to manage website content, we often encounter situations where we need to precisely control the display range of documents.For example, when you want to display only the documents directly published in a parent category page, without involving the content of its subcategories, you need to adjust the way the document list is obtained.AnQi CMS provides a very flexible API interface, allowing you to easily meet this requirement.
Ensure that the document list obtained only contains content under the parent category and automatically excludes all documents under subcategories, the key lies in cleverly utilizingarchiveListthe interface incategoryIdandchildthese two parameters.
First, you will use the Anqi CMSto get the document list interface, and its API call address is{域名地址}/api/archive/list. This is a powerful interface that allows you to filter and sort documents according to multiple conditions.
When you specify acategoryIdUnder normal circumstances, the Anqi CMS will be "smart" enough to return all documents under the category and all its subcategories.This is very convenient when building an aggregated page.However, if your design intention is to only display the direct content of the current category, this default behavior may not be very suitable.
at this point,childThe parameters come into play.childthe parameter is a boolean, which determines whether to include documents of all subcategories. Its default value istrueThis means it will include subcategories. When you need to limit the scope, only the current specifiedcategoryIddocument needs to be selected.childthe parameter tofalse.
For example, suppose your website has a parent category named "News Center," itscategoryIdWith100.Under the 'News Center', there may be subcategories such as 'Domestic News', 'International News', and so on.
GET {域名地址}/api/archive/list?categoryId=100&child=false
Through such a request, Anqi CMS will accurately filter out thosecategory_idExactly is100The document, while allparent_idWith100(i.e., the subcategory of 'News Center') documents will be cleverly excluded.
This fine control capability is of great significance for content operations.It allows you to present the most relevant and related content based on the specific functions of the page and the user's browsing habits.child=true(or omittedchildParameters to fully present all relevant content. This flexibility ensures the clarity of the website's content structure and the optimization of user experience.
Frequently Asked Questions (FAQ)
Q1: How can I display the documents of a specified category and all its subcategories?A1: If you want to get all documents under a specified category, including documents in its subcategories, you can omitchildthe parameter, or explicitly set it tochild=truebecausetrueIschildThe default behavior of parameters. For example:GET {域名地址}/api/archive/list?categoryId=100It can achieve this effect.
Q2: Can I get documents from multiple parent categories at the same time, and also exclude the subcategories of these parent categories?A2: OK.categoryIdThe parameter supports passing multiple category IDs separated by commas. So, you can construct the request like this:GET {域名地址}/api/archive/list?categoryId=100,101,102&child=falseThis will return.categoryIdWith100/101or102The direct document, which will not include any documents in the subcategories of these categories.
Q3: Thischild=falseParameter whether it also applies to retrieving the document list by model ID (moduleId)?A3: Yes,child=falseThe parameter mainly relates tocategoryIdCombine them to control the document inclusion relationship of a specific category level.moduleIdUsed to filter all documents under a specific document model (such as articles, products, etc.). You can first go throughmoduleIdSpecify the document model and then proceed throughcategoryIdandchild=falseFurther refine the filtering results. For example:GET {域名地址}/api/archive/list?moduleId=1&categoryId=100&child=falseRetrieve the document under the article model and directly belongs to the category ID 100.