When operating a website, we often encounter such a need: when displaying the website category list, we hope to be able to see directly how many articles are under each category.This not only helps visitors quickly understand the richness of a topic's content, improve user experience, but also allows content operators to better plan content strategies, and even has its unique value in SEO optimization.
Then, does AnQiCMS support displaying the number of articles under each category on the category list page? The answer is yes, and it can be implemented very conveniently.
In AnQiCMS template design, if you want to clearly show how many articles are included under each category in the category list page, it is actually very intuitive.This is mainly due to the powerful and flexible template tag system of AnQiCMS.categoryListLabels are designed to obtain category lists, and they thoughtfully include the article count under each category while returning each category's information.
Specifically, when you are iterating over the category list in a template, for example using{% categoryList categories with ... %}such tags to get category data,categorieseach variable initemAll represent a specific category and carry rich category information. Among them, there is one namedArchiveCountThis field accurately records the total number of documents under this category (usually including its subcategories).
This means, you do not need to perform additional database queries or complex logic processing. When you retrieve and display category names, category links, and other information in the template, you simply need to call{{ item.ArchiveCount }},can display the corresponding number of articles on the page, for example, displayed as "Technical Articles (123)" or "Product Cases (45)."This built-in support greatly simplifies the work of development and maintenance.
It is worth mentioning that,categoryListThe label itself supports various parameters to finely control the range of categories obtained, such as throughmoduleIdParameters to specify to retrieve only specific content models (such as article models or product models) categories, or throughparentIdLimit to retrieve only the child categories under a certain parent category. No matter how you filter and organize the categories,ArchiveCountthe corresponding number of accurate articles under the category will be provided.
In essence, AnQiCMS, with its meticulously designed template tags and flexible content model, makes it a simple and practical feature to display the number of articles on category list pages, effectively supporting the management and presentation of website content.
Common Questions (FAQ)
Is this article count update in real time?Yes, it is in AnQiCMS.
ArchiveCountThe field is dynamically retrieved, and it queries the number of articles under the category in the database in real time.This means that after you publish, delete, or move an article, the number of articles displayed on the category list page will be updated immediately, ensuring the accuracy of the information.If there are no articles under a category currently,
ArchiveCountWhat will be displayed?If there are no articles under a category currently,ArchiveCountIt will naturally display as0. You can make a decision based on this value in the template, for example,ArchiveCountThe number is 0, you can choose not to display the number of articles, or display prompts such as 'No articles available' to keep the page clean or provide a more friendly user tip.Can I use
categoryListHow to count the number of categories under a specific content model (such as “product” rather than “article”)?Absolutely.categoryListtag supportmoduleIdParameters, you can throughmoduleId="1"(Assuming the ID of the article model is 1) ormoduleId="2"To specify the category list you want to retrieve, use the ID of the product model (assuming it is 2). This way,ArchiveCountThe field will only count the number of articles under the specified model, providing you with more accurate content statistics.