Can the `categoryList` tag display the number of documents under each category? How can `item.ArchiveCount` be retrieved and displayed?

Calendar 👁️ 65

As an experienced website operations expert, I know that how to efficiently and intuitively display content data in a content management system is the key to improving user experience and content operation efficiency.AnQiCMS (AnQiCMS) with its concise and efficient architecture, provides us with great flexibility.Today, let's delve deeply into a question that both operators and template developers are very concerned about: categoryListCan the tag display the number of documents under each category?item.ArchiveCountHow to obtain and display?”


AnQi CMS: How to usecategoryListwithitem.ArchiveCountImprove the efficiency of displaying category content

On an AnQi CMS-built website, a clear, richly contented, and guiding category list can greatly facilitate users in discovering and browsing the content they are interested in.Imagine if your category list could not only display the category names but also clearly tell visitors how many excellent articles or products are under each category, which would undoubtedly greatly enhance user experience and the efficiency of content discovery.The good news is that AnQi CMS has fully considered this requirement and provided a straightforward and easy-to-use method to achieve it.

categoryListSecret of the 'Content Quantity' in the category list

The Anqi CMS template system is designed to be very flexible and powerful, with its core lying in a series of rich and easy-to-understand tags. Among them,categoryListTags are the key tools used to retrieve and display category lists.

When we usecategoryListWhen traversing the categories of a website, Anqi CMS not only returns basic information about the categories, such as ID, title, link, etc., but also thoughtfully provides you with a category namedArchiveCountThe attribute. This attribute directly stores the total number of documents (articles, products, or other content models) associated with the category.

This means, you do not need to perform additional complex queries or calculations, just simply callitem.ArchiveCountIt can display the number of documents under each category in the category list in real time.This provides great convenience for building a more dynamic and user-friendly navigation system, or creating a data-driven classification overview page.

Let's take a specific example to see how to implement this in a template. Suppose we want to display all top-level categories under the article model on the homepage and also show the number of articles under each category:

{# 使用categoryList标签获取文章模型(moduleId="1")下的所有顶级分类(parentId="0") #}
{% categoryList categories with moduleId="1" parentId="0" %}
    <div class="category-section">
        <h3>内容分类</h3>
        <ul>
            {% for item in categories %}
                <li>
                    {# 显示分类名称,并紧随其后展示该分类下的文档数量 #}
                    <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
                    <span class="archive-count">({{ item.ArchiveCount }} 篇文档)</span>
                </li>
            {% endfor %}
        </ul>
    </div>
{% endcategoryList %}

In the code above,item.ArchiveCountOutput the total number of documents contained in the current category loop.In this way, visitors can quickly understand the depth of content in each category, thereby better deciding which category to click for in-depth browsing.

categoryDetail: Accurately obtain the number of documents in a single category

Sometimes, we may need to obtain and display the number of documents in a specific area on a page, or for a known category ID, independently of the list loop.For example, you may recommend related categories in the sidebar of the article detail page and want to display the number of documents in that category. At this time,categoryDetailthe label comes into play.

categoryDetailTags allow you to access the details of a single category by its ID (id) or URL alias (token) to obtain the details of a single category. LikecategoryListtags, when you usecategoryDetailYou can also get the details of the category byArchiveCountusing the property to get the number of documents under the category.

Here is an example of how to retrieve and display the title and document count of a category with ID "5" in a template:

{# 通过id参数获取ID为5的分类详情 #}
<div class="featured-category">
    <h4 class="category-title">
        {# 直接输出ID为5的分类标题 #}
        <a href="{% categoryDetail with name="Link" id="5" %}">{% categoryDetail with name="Title" id="5" %}</a>
    </h4>
    <p class="category-info">
        该分类下共有:<strong class="count-number">{% categoryDetail with name="ArchiveCount" id="5" %}</strong> 篇精彩内容。
    </p>
</div>

In this scenario,{% categoryDetail with name="ArchiveCount" id="5" %}The number of documents in the category with ID 5 is returned directly, without going through the loop, which is very suitable for accurately displaying information about a single category.

Considerations and suggestions in practice

  1. moduleIdimportanceIn AnQi CMS, content is managed based on 'models' (for example, article models, product models). When callingcategoryListorcategoryDetailspecify explicitlymoduleIdThe parameter is crucial. This ensures that you get the categories and document counts under a specific content model.If not specified, the system may default to retrieving all categories under all models, which may cause data to become disorganized or inaccurate.

  2. User experience optimization: When designing the interface, you can consider presenting the number of documents in a clear and unobtrusive manner.For example, use small font, parentheses to enclose, or display more information when hovering.This can help users quickly assess the amount of content in a category, thus making more informed browsing choices.

  3. Performance considerationDue to the high-performance architecture of the underlying Go language in AnQi CMS and its efficient data query mechanism, retrieving and displaying the number of these documents will not significantly affect the website's loading speed.The system will optimize data retrieval in the background to ensure that your website remains smooth.

  4. Template File LocationYou can use these tags in any template file on the website (such asindex.html/list.html/detail.htmlor publicpartial/header.html/partial/footer.htmletc.) to flexibly layout according to your design requirements.

Summary

Through its intuitive template tags, AnQi CMS allows website operators and template developers to easily display the number of documents under each category in a category list or specific area. Whether it is bycategoryListThe loop iteration, orcategoryDetailThe precise positioning,item.ArchiveCount(Or direct)ArchiveCountProperties provide us with rich content display possibilities.Make good use of these features, not only can it improve the content organization and navigation efficiency of the website, but also bring users a more intelligent and convenient browsing experience.


Frequently Asked Questions (FAQ)

1. If there are no documents under a category currently,item.ArchiveCountwhat will be displayed?Answer: If there are no documents under a category,item.ArchiveCountIt will display0This meets the expectation, it can clearly inform the user that this category currently has no content. You can also use the template to{% if item.ArchiveCount > 0 %}To determine whether to display the document count, or display a different prompt when the count is 0.

2. I want to display the number of documents under a specific content model (such as "Product Model") in the category list, rather than all types of documents. How should I operate?Answer: You need to providecategoryListExplicitly specify in the tagmoduleIdthe parameters. For example, if your product model ID is2, then you should call it like this:{% categoryList categories with moduleId="2" parentId="0" %}Thus,item.ArchiveCountIt will only count and display the number of documents belonging to the "Product Model" category under this category.

3.ArchiveCountDoes the count of documents include drafts or unpublished documents?Answer: Generally speaking, the Anqi CMS'sArchiveCountThe property defaults to only counting published, publicly visible documents. Drafts, pending review, or deleted (moved to the recycle bin) documents will not be included in this count to ensure that the data displayed on the website's frontend is accurate and user-facing.If you need to count all the document statuses, it usually requires through the backend API or deeper template customization implementation.

Related articles

How can you determine if a category has a subcategory? How can the `item.HasChildren` field be applied to conditional judgments?

As an experienced website operations expert, I deeply understand the importance of efficiently using template tags in the daily application and content strategy formulation of AnQiCMS (AnQiCMS).Today, let's delve deeply into a very practical topic in website structure construction: how to determine whether a category (Category) contains subcategories, and how to cleverly use the `item.HasChildren` field in templates to achieve intelligent content display.

2025-11-06

What do `categoryList` loop's `item.Title` and `item.Link` represent, and how to output?

As an experienced website operations expert, I know that how to efficiently and accurately extract and display data in a content management system is the cornerstone of website success.AnQiCMS is an enterprise-level content management system based on the Go language, and its simple and efficient template engine is very appealing to me.Today, let's delve deeply into what `categoryList` loop's `item.Title` and `item.Link` represent in AnQiCMS template development, and how we can elegantly present them in the template.### Reveal

2025-11-06

How do I correctly use the `all=true` parameter of `categoryList` to display all categories in the sidebar?

In Anqi CMS, efficiently managing and displaying website content is the key to operational success.The sidebar acts as an important navigation area for websites, often needing to display clear categories to guide users quickly to the information they need.When you want to display all categories in the sidebar and are puzzled by the `all=true` parameter of the `categoryList` tag, this is exactly the topic we will delve into today.In AnQi CMS, categories are the framework for organizing website content.

2025-11-06

Does the `categoryList` tag support limiting the number of categories returned? How to set the `limit` parameter?

As an experienced website operations expert, I know how important it is to have precise control over content display when building and optimizing a website.AnQiCMS as an efficient and flexible content management system, its powerful template tag system provides us with abundant operating space.Today, let's delve into the function of the `categoryList` tag in limiting the number of returned categories, as well as how to巧妙ly use the `limit` parameter.

2025-11-06

How to display a category thumbnail (`item.Thumb`) or Banner image (`item.Logo`) next to the category list?

As an experienced website operation expert, I am well aware of the importance of the visual presentation of website content in terms of user experience and information delivery.In a powerful and flexible system like AnQiCMS, we have multiple ways to achieve fine-grained content control, especially in key navigation areas like category lists. How to effectively display category thumbnails or Banner images is an important aspect to enhance the professionalism and attractiveness of a website.Today, let us delve into how to cleverly integrate these visual elements into the category list in Anqi CMS.--- ###

2025-11-06

What is the actual use of the `item.Spacer` field in multi-level category display, and how to beautify the prefix?

As an experienced website operations expert, I know that every seemingly minor feature in a content management system may play a key role in user experience and content presentation.Today, let's delve deeply into a frequently overlooked but indispensable field in AnQiCMS, which is essential for building a clear and hierarchical content structure - `item.Spacer`.

2025-11-06

How to highlight the category link being accessed according to the `item.IsCurrent` field?

As an experienced website operations expert, I know that user experience is the foundation of website success.How to help visitors quickly locate their current position on a content-rich website and clearly understand the navigation structure is the key to improving user satisfaction.Today, let's delve deeply into a very practical and elegant feature of Anqi CMS - how to cleverly highlight the current category link accessed using the `item.IsCurrent` field, thereby significantly optimizing the navigation experience of the website.

2025-11-06

Can the `categoryList` tag return the `item.Description` field for SEO description on the category page?

In website operation, the SEO description (Meta Description) of the category page is one of the key elements to improve search engine ranking and click-through rate.A well-written description that not only accurately summarizes the page content but also attracts users to click.For website administrators and content operators using AnQiCMS, how to efficiently and accurately utilize the system functions to manage these descriptions is a common issue.Today, let's delve deeply into a specific issue: `categoryList` tag returns the `item'

2025-11-06