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.