As an experienced website operation expert, I know that how to effectively and intuitively present content data in a content management system is the key to improving user experience and content operation efficiency.AutoCMS (AutoCMS) provides us with great flexibility with its simple and efficient architecture.categoryListLabel whether to display the number of documents under each category?item.ArchiveCountHow to obtain and display?


[en]Safe CMS: Make good use ofcategoryListWithitem.ArchiveCountImprove the efficiency of displaying category content

On a website built with AnQi CMS, a clear, content-rich 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 category names but also clearly tell visitors how many excellent articles or products are under each category, this 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 an intuitive and easy-to-use method to achieve it.

categoryListThe 'Content Quantity' in the category list is a secret.

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

When we usecategoryListWhen traversing the categories of a website, AQCMS not only returns the basic information of the category, such as ID, title, link, etc., but also provides a category name namedArchiveCountThis property directly stores the total number of documents (articles, products, or other content models) associated with this category.

This means, you do not need to perform any additional complex queries or calculations, just simply callitem.ArchiveCount,就能在分类列表中实时显示每个分类下的文档数量。This provides great convenience for building a more dynamic and user-friendly navigation system, or for creating data-driven overview pages.

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 home page of the website, 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 above code,item.ArchiveCountThe total number of documents contained in the current category being cycled through is output directly.By this means, visitors can quickly understand the depth of content in each category, thereby better deciding which category to click for further browsing.

categoryDetail:Englishly obtain the number of documents in a single category.

In addition to displaying in the list loop in bulk, sometimes we may need to obtain and display the document count separately in a specific area of the page, or for a known category ID.For example, you may recommend related categories in the sidebar of the article detail page and wish to display the number of documents in that category.categoryDetailLabels come in handy.

categoryDetailTags allow you to retrieve the details of a single category by its ID ()id), or URL alias (token) to obtain the details of a single category. Like the tag, when you usecategoryList categoryDetailGet category details, you can also get the number of documents under the category byArchiveCountthe attribute.

The following is an example demonstrating how to retrieve and display the title and document count of the 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" %}Directly returns the document count of the category with ID 5, without going through a loop, which is very suitable for accurately displaying information of a single category.

Considerations and suggestions in practice

  1. moduleIdThe importance of: In the AnQi CMS, content is managed based on 'models' (such as, article model, product model). When callingcategoryListorcategoryDetail,specify explicitlymoduleIdThe parameter is crucial.This ensures that you get the number of categories and documents under a specific content model.If not specified, the system may default to retrieving all categories under all models, which may lead to disordered or inaccurate data.

  2. User experience optimization In designing the interface, consider presenting the number of documents in a clear and non-obtrusive manner.For example, use small font, enclosed in parentheses, or display more information on mouse hover.This can help users quickly assess the content volume of the classification, thus making more informed browsing choices.

  3. Performance considerations: Benefiting from the high-performance architecture of the underlying Go language and efficient data query mechanism of Anqi CMS, retrieving and displaying these document quantities 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. Location of template file: You can use these tags in any template file on the website (such asindex.html/list.html/detail.htmlor publicpartial/header.html/partial/footer.htmletc.), and flexibly layout according to your design requirements.

Summary

The Anqi CMS enables website operators and template developers to easily display the number of documents under each category in category lists or specific areas through its intuitive template tags. Whether throughcategoryListThe loop iteration, orcategoryDetailThe precise positioning,item.ArchiveCount(Or direct),ArchiveCountAll properties provide 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.


Common Questions and Answers (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.ArchiveCountwill be displayed0This meets the expectation, it can clearly inform the user that there is currently no content in this category. You can also inform the user in the template.{% if item.ArchiveCount > 0 %}To determine whether to display the document count, or to 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 documents of all types. How should I operate?答:You need tocategoryListspecify in the tag.moduleIdthe parameters. For example, if the ID of your product model is2,then you should call it like this:{% categoryList categories with moduleId="2" parentId="0" %}like this,item.ArchiveCountIt will only count and display the number of documents belonging to the category “Product Model”.

3.ArchiveCountHow many documents are counted, including drafts or unpublished documents?Answer: In most cases, the Anqi CMSArchiveCount