In website operation, the content display logic of the category page has an important impact on user experience and information architecture.We often encounter such needs: when there are subcategories under a category, it is preferable to display these subcategories to facilitate more detailed navigation;And if the category does not have any subcategories, then directly display the list of articles under the category, to avoid the page content being empty or the navigation hierarchy being too deep.AnQiCMS (AnQiCMS) provides flexible template tags that can easily achieve this dynamic display effect.
Understanding the dynamic display logic of the category page
To implement the intelligent display of the category page, the core lies in determining whether the current category has subcategories. Based on the judgment result, we adopt different display strategies:
- If there are subcategories:Display all subcategories under the current category, usually presented in a list or card format, guiding users to more specific categories.
- If there are no subcategories:Display the list of articles included in the current category, allowing users to browse the content directly.
This design can effectively improve the usability of the website, allowing users to find valuable information at any level of the category page, rather than seeing an empty page.
The key template tag for dynamic display in Anqi CMS
The AnQi CMS template system is based on the Django template engine syntax, providing powerful tag functions for data retrieval and processing. To implement the above logic, we need to use the following core tags:
categoryDetailTags:Used to obtain the details of the current category. We can use it to obtain the ID of the current category to pass as a parameter to other tags.- Usage example:
{% categoryDetail currentCategory %}(Get the complete object of the current category) or{% categoryDetail currentCategoryId with name="Id" %}(Only get the ID of the current category).
- Usage example:
categoryListTags:Used to get the category list, which is the key we use to find subcategories.- Main parameters:
parentId: Specify the parent category ID to retrieve its direct subcategories. When used on the category page, if the current category ID is passed in, it can obtain all subcategories of the current category.moduleId: Specify the content model ID to ensure that the classification of a specific model is obtained (such as article model, product model).
- Return properties:While traversing
categoryListreturneditem, each classification item includesId/Title/Linkand other information.
- Main parameters:
archiveListTags:Used to retrieve a list of articles (or any content under a document model).- Main parameters:
categoryId: Specify the category ID to get articles under the specified category.type: Usually set to"list"(to get a fixed number) or"page"Get a paged list.limit: Limit the number of articles.
- Return properties:Traversal
archiveListreturneditemEach article item includes whenId/Title/Link/Description/Thumband other information.
- Main parameters:
4