In website operation, we often need to flexibly display content, such as displaying the latest articles on a page, but not including the content of certain specific categories, such as announcements or internal news.AnQiCMS as a powerful content management system, provides a rich set of API interfaces to meet these complex display requirements.archive/listAn interface parameter that is very practical:excludeCategoryIdEspecially how it supports the exclusion of multiple categories of documents at the same time.
excludeCategoryIdThe clever use of the parameter: accurately exclude documents of multiple categories
When you usearchive/listInterface to retrieve document list,excludeCategoryIdParameters play a vital role in content filtering.Its design intention is to allow you to precisely control which categories of documents are not displayed in the results.stringType, and its key characteristics are:Multiple category IDs can be separated by English commas,separated.
This means, if you wish to exclude documents with category ID of5/8and12, you just need to setexcludeCategoryIdparameter.5,8,12English.The system will intelligently filter out all content under these three categories in the returned results after receiving this parameter, thus greatly simplifying the fine-grained management and display logic of the content.
For example, if you want to retrieve 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
By this means, 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 operation of website content, which can help us organize and display content more efficiently:
- Personalized Content DisplayIn the "Latest News" or "Recommended Content
- Optimization related recommendationsIn the article detail page, the module of "Related Articles" or "You may also like" is usually displayed at the bottom. Utilize
excludeCategoryIdYou can exclude the category to which the current article belongs (to avoid self-promotion) or exclude some outdated, inactive categories, thereby ensuring the quality of recommended content and user experience. - Content Management and TestingIn A/B testing, it may be necessary to display different sets of content to different user groups, which may involve excluding certain specific categories. In addition, in some special content management scenarios, it may be necessary to temporarily hide the content of a certain category without deleting or modifying the category itself.
excludeCategoryIdIt can be put to good use. - Simplify the front-end logic:Front-end developers do not need to filter all data before obtaining it. They can directly complete the preliminary screening 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
When usingexcludeCategoryIdWhen the parameter is set, there are some details that need to be paid attention to to ensure its correct and effective operation:
- Parameter type and formatAlways set
excludeCategoryIdThe value is treated as a string, even if only one category is excluded, it is recommended to write itexcludeCategoryId=5InsteadexcludeCategoryId=5. Always use English commas between multiple IDs,Separate with commas, avoid spaces or other non-numeric characters, which may cause parsing errors. - Combine
categoryIdUse:excludeCategoryIdCan be used withcategoryIdParameters are used at the same time. For example, you can specifycategoryId=1,2,3To explicitly include documents that contain these three categories, and then further throughexcludeCategoryId=2To exclude documents from these three categories where the category ID is 2. This provides great flexibility for building complex filtering logic. - Note
childParameters:AnQiCMS 的archive/list接口中还有一个child参数,默认为true,表示在查询categoryId时会自动包含其子分类的文档。如果你的excludeCategoryIdThis contains an ID of a parent category, which will exclude only the parent category itself and will not automatically exclude all its subcategories unless the IDs of these subcategories are also explicitly listed.excludeCategoryIdauto. If you only want to exclude specific categories without affecting their parent or child categories, please consider carefully.categoryIdandchildauto. - auto.auto, it is recommended to go through first in actual development.
category/listThe interface retrieves the required category ID and dynamically constructsexcludeCategoryIdparameters to avoid hardcoding and potential errors.
In short, AnQiCMS'sarchive/listprovided by the interfaceexcludeCategoryId参数是一个强大而灵活的工具,它让网站运营者和开发者能够以前所未有的方式控制文档列表的显示,实现更智能、更符合用户需求的内容呈现。Mastering this usage will effectively enhance the content operation efficiency and user experience of your website.
Common Questions and Answers (FAQ)
Q1:excludeCategoryIdwhether it can be used withcategoryIdat the same time?
A1:Yes,excludeCategoryIdandcategoryIdThese two parameters can be used simultaneously to achieve more refined filtering control. For example, if you specifycategoryId=10,11,12to retrieve documents under these three categories, and also setexcludeCategoryId=11Then the final 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, just by specifying the parent category's ID inexcludeCategoryIdIs it valid?
A2: excludeCategoryIdIt is to exclude the specified category ID explicitly.archive/listthe interface'schildThe parameter (default is)true)生效,categoryIdThis will include its subcategories. Therefore, if you want to exclude a parent category and all its subcategories, the safest approach is to get all the subcategory IDs under the parent category, and then list these IDs along with the parent category's IDexcludeCategoryIdParameters are separated by commas.
Q3:excludeCategoryIdDoes the parameter affect performance? How many category IDs can I exclude?
A3:Any filtering parameter will have a certain impact on the database query.excludeCategoryIdAlso applicable. Generally, excluding a small or moderate number of classification IDs will not cause significant performance issues. It is not explicitly stated in the AnQiCMS documentation.excludeCategoryIdThe maximum number of acceptable category IDs.But in practical use, if the number of categories to be excluded is very large, it may have a certain impact on query efficiency.In this extreme case, it may be necessary to consider optimizing the classification structure or adjusting the content display logic.Suggest to perform thorough testing before deploying to production environment.