In website operation, we often need to display content flexibly, such as displaying the latest articles on a page, but not including content from certain specific categories, such as announcements or internal news.AnQiCMS as a powerful content management system, provides a wealth of API interfaces to meet these complex display requirements.Today, let's delve intoarchive/listAn extremely practical parameter in the interface:excludeCategoryIdEspecially how it supports excluding multiple categories of documents simultaneously.
excludeCategoryIdThe magic of the parameter: precisely excluding multi-category documents.
When you usearchive/listThe interface to get the document list isexcludeCategoryIdParameters play an important role in content filtering. Its original intention is to allow you to precisely control which categories of documents are not displayed in the results.According to the official documentation of AnQiCMS, this parameter is defined asstringType, and its key feature lies in:Multiple category IDs can be separated by English commas,with.
This means, if you want to exclude all documents with category ID of5/8and12just setexcludeCategoryIdThe parameter value is set to5,8,12It is done. After receiving this parameter, the system will intelligently filter out all content under these three categories in the returned results, thereby greatly simplifying the fine-grained management and display logic of the content.
For example, if you want to get all documents with model ID 1 but do not want to include content with category ID 5 and 8, your API request can be constructed as follows:
GET {域名地址}/api/archive/list?moduleId=1&type=page&excludeCategoryId=5,8
In this way, you can easily obtain a list of documents excluding a specific category.
Why is this feature so practical?
This feature has a very wide range of application scenarios in the actual website content operation, and can help us organize and display content more efficiently:
- Personalized content displayIn the "Latest News" or "Recommended Content" module on the homepage, you may want to display all the latest articles, but need to exclude specific categories such as "Company Announcements" or "Marketing Activities" to maintain the professionalism and focus of the homepage content.
- Optimize related recommendations: Usually, under the article detail page, modules such as "related articles" or "you might also like" will be displayed. Using
excludeCategoryIdYou can exclude the category of the current article (to avoid self-promotion) or exclude some outdated, inactive categories to ensure the quality and user experience of the recommended content. - Content management and testingIn A/B testing, it may be necessary to display different content sets to different user groups, which may involve excluding certain specific categories of content. In some special content management scenarios, it is necessary to temporarily hide the content of a certain category without deleting or modifying the category itself,
excludeCategoryIdCan be put to use. - Simplify front-end logic: Front-end developers do not need to filter all data after obtaining it, they can directly complete preliminary filtering through API parameters, which reduces the amount of data transmission and the complexity of front-end processing, and improves the page loading efficiency.
Implementation suggestions and precautions
While usingexcludeCategoryIdWhen setting parameters, there are some details to note to ensure that they function correctly and effectively:
- Parameter type and format: Always set
excludeCategoryIdThe value is considered a string, even if only one category is excluded, it is recommended to be written asexcludeCategoryId=5instead ofexcludeCategoryId=5ID's must be separated by English commas.,Separate with commas, avoid spaces or other non-numeric characters, which may cause parsing errors. - Combine
categoryIdUse:excludeCategoryIdCan be used withcategoryIdParameters can be used at the same time. For example, you can specifycategoryId=1,2,3To explicitly include documents of these three categories, and to pass throughexcludeCategoryId=2To exclude documents from these three categories with category ID 2. This provides great flexibility for building complex filtering logic. - Note
childParameter: AnQiCMS'archive/listThere is also anotherchildparameter, the default istrueindicating that in the querycategoryIdit will automatically include the documents of its subcategories. If yourexcludeCategoryIdIt includes the ID of a parent category, which will only exclude the parent category itself and will not automatically exclude all its subcategories unless the IDs of these subcategories are also explicitly listed.excludeCategoryIdIn. If you only want to exclude a specific category without affecting its parent or child categories, please consider it carefully.categoryIdandchildthe combination of parameters. - First, get the category ID: In actual development, it is recommended to go through first.
category/listThe interface retrieves the required category ID and dynamically constructsexcludeCategoryIdparameters to avoid hardcoding and potential errors.
In short, AnQiCMS'sarchive/listprovided by the interfaceexcludeCategoryIdThe parameter is a powerful and flexible tool that allows website operators and developers to control the display of document lists in unprecedented ways, achieving smarter and more user-friendly content presentation.Mastering this usage will effectively enhance the content operation efficiency and user experience of your website.
Frequently Asked Questions (FAQ)
Q1:excludeCategoryIdCan it be used withcategoryIdat the same time?
A1:Yes,excludeCategoryIdandcategoryIdThese two parameters can be used simultaneously to achieve more fine-grained filtering control. For example, if you specifycategoryId=10,11,12to retrieve documents under these three categories, and at the same time setexcludeCategoryId=11In the end, the document will only contain the content of categories 10 and 12, and the documents of category 11 will be excluded.
Q2: I want to exclude all child categories under a certain parent category, is it valid to only specify the parent category's ID inexcludeCategoryId?
A2: excludeCategoryIdIt is to exclude the specified category ID explicitly. Ifarchive/listinterface'schildParameters (default totrue)is effective,categoryIdIt will include its subcategories. Therefore, if you want to exclude a parent category and all its subcategories, the safest way is to get all the subcategory IDs under the parent category and then include these IDs along with the parent category ID.excludeCategoryIdParameters should be separated by commas.
Q3:excludeCategoryIdDoes the parameter affect performance? How many category IDs can I exclude?
A3:Any filtering parameter will have an impact on the database query.excludeCategoryIdAlso, in most cases, excluding a small or moderate number of category IDs will not cause significant performance issues. The AnQiCMS documentation does not explicitly state this.excludeCategoryIdThe maximum number of acceptable category ID. However, in actual use, if a large number of category IDs need to be excluded, it may have an impact on query efficiency.In such extreme cases, it may be necessary to consider optimizing the classification structure or adjusting the content display logic.It is recommended to conduct sufficient testing before deploying to the production environment.