How to get the link, Logo image, and document count in the `categoryList` loop?

Calendar 👁️ 57

As an experienced website operations expert, I fully understand the importance of an efficient and flexible content management system for daily operations.AnQiCMS with its high-performance architecture based on the Go language and the friendly syntax of the Django template engine, provides us with great convenience.Today, let's explore a very practical technique in website front-end display: how tocategoryListElegantly obtain the link, Logo image, and the number of documents under the category in a loop.

In the AnQiCMS template system,categoryListTags are specifically used to retrieve and display website category information. Whether you need to list top-level article categories or subcategories under a specific category,categoryListCan be handled flexibly. It allows us to filter categories by module ID (moduleId) or parent category ID (parentId) to build various complex navigation and content organization structures.

Once we pass throughcategoryListLabel gets the collection of classified data, the next task is to traverse these data, and display them on the web page. Here,forThe loop tag is particularly important, as it allows us to process each category item one by one. Typically, we will assign the obtained category list to a variable (such ascategories),thenforLoop and name each category itemitemSo you can easily access the properties of each category.

Easily get the exclusive link of the category

Each category carries a unique path to its detail page, incategoryListthe loop, you can access{{item.Link}}Property, easily obtain the exclusive link of each category. This link is the accessible URL after AnQiCMS static rule processing, ensuring SEO friendliness and user experience.Just put it in<a>label'shrefin the properties, a clickable category navigation item appears before your eyes.

Accurately display the Logo and thumbnail of the category

Visual elements are crucial for enhancing user experience, especially for categorization identifiers.AnQiCMS has taken this into consideration in the category settings, allowing upload of Logo images and thumbnails for each category.categoryListthe loop,{{item.Logo}}Will provide you with the address of the large image or Banner image of the category, usually used in prominent positions or scenes requiring high-quality image display.{{item.Thumb}}It is usually used to display category thumbnails processed automatically by the system or set by the background, suitable for areas that need small-sized images such as lists, sidebars, etc. You can choose to use one according to the page layout and design requirements, and even judge first.LogoDoes it exist, if not, fallback toThumbTo ensure that the page always has appropriate images displayed.

A clear count of the number of documents

In addition to links and images, operators often also need to know how many documents are under each category.categoryListin the loop{{item.ArchiveCount}}The attribute directly returns the total number of documents under the category (and its subcategories, if not specially configured).This data is very helpful for creating a category list with statistical information, such as displaying information like "Tutorial (123 articles)" or "Product Category (50 models)", which can enhance users' expectations and interest in the category content.

Integration Application: Build Dynamic Category Lists

Let's take a comprehensive example that integrates all the information mentioned above into a typical classification list, helping you understand how they work together clearly.

{% categoryList categories with moduleId="1" parentId="0" %}
    <ul class="category-list">
    {% for item in categories %}
        <li class="category-item">
            <a href="{{ item.Link }}" class="category-link">
                {# 优先显示Logo图,如果没有则显示缩略图 #}
                {% if item.Logo %}
                    <img src="{{ item.Logo }}" alt="{{ item.Title }} Logo" class="category-logo">
                {% elif item.Thumb %}
                    <img src="{{ item.Thumb }}" alt="{{ item.Title }} 缩略图" class="category-thumb">
                {% else %}
                    {# 如果两者都没有,可以显示一个默认占位符或文本 #}
                    <span class="category-icon-placeholder">{{ item.Title|slice:":1" }}</span>
                {% endif %}
                <h3 class="category-title">{{ item.Title }}</h3>
                <span class="document-count">({{ item.ArchiveCount }} 篇文档)</span>
            </a>
            {# 这里可以根据需要添加子分类的嵌套循环 #}
            {% if item.HasChildren %}
                {# 例如:{% categoryList subCategories with parentId=item.Id %}...{% endcategoryList %} #}
            {% endif %}
        </li>
    {% endfor %}
    </ul>
{% endcategoryList %}

In this code snippet, we first usecategoryListthe tag to get the article model(moduleId="1") under all top-level categories(parentId="0")。In each iteration of the loop,item.Linkthe access link of the category was generated,item.Logooritem.ThumbResponsible for displaying the visual identification of the category (an additional simple logic is added here, which displays the first letter of the title as a placeholder when neither Logo nor Thumb exist), anditem.ArchiveCountIt clearly shows the number of articles in the category.

Master these skills, and you will be able to build a beautiful and informative category list in AnQiCMS, greatly enhancing the organization of website content and user navigation experience.The AnQiCMS template system, with its intuitive tags and powerful data access capabilities, is indeed a rare good helper for content operators.


Frequently Asked Questions (FAQ)

Question:item.Logoanditem.ThumbWhat are the differences in practical application? How should I choose to use it?

Answer:item.LogoIt usually returns the complete address of the large image or Banner image you upload in the background, suitable for use at the top of the page, in the focus area, or when a larger, more expressive image is needed.item.ThumbIt returns the thumbnail address automatically processed by the AnQiCMS system or the one you set in the background, which is usually smaller in size and more suitable for scenarios where space and quick loading are needed, such as lists, sidebars, navigation menus, etc.You can flexibly choose to use it according to the specific page layout and design requirements, and even set a priority as shown in the article example to ensure that there is an alternative solution when one image is missing.

Question:item.ArchiveCountHow many documents include subcategories? What if I want to count only the documents under the current category?

Answer: By default,item.ArchiveCountCounts the total number of documents under the current category and all its subcategories. This is very convenient when building comprehensive category statistics. AnQiCMS'scategoryListIt is mentioned in the tag document,ArchiveCountThe calculation is the total number of documents under the category (and its subcategories, if not specifically configured). If you want to count the number of documents under the current category only and not include subcategories, you need toarchiveListExplicitly specify in the tagchild=falseTo get the document list, then manually calculate, or check the category detail tagscategoryDetailIs there a field for the number of documents in the current category (the document is not explicitly stated, but it is usually provided by CMS).

Question: If the category does not have a logo image or thumbnail uploaded,item.Logoanditem.ThumbWhat will be returned? How should I handle this situation?

Answer: If the category does not upload the corresponding Logo image or thumbnail,item.Logoanditem.ThumbThe property usually returns an empty string. To avoid blank spaces or errors on the page when images are missing, you can add conditional judgments in the template. For example, using{% if item.Logo %}Check if the Logo exists, if not

Related articles

how the `categoryList` tag implements nested hierarchical display of multi-level categories?

Sure, as an experienced website operations expert, I am happy to deeply analyze how to implement nested display of multi-level categories in the `categoryList` tag of AnQi CMS and transform it into an article that is easy to understand and practical. --- ## AnQi CMS `categoryList` Tag: Easily Implement Nested Display of Multi-level Categories, Making the Website Structure Clear and Orderly A clear classification system is crucial for user experience (UX) and search engine optimization (SEO) in website operations.

2025-11-06

How to get all top-level categories under a specified model for the `categoryList` tag?

Anqi CMS, as an efficient and customizable enterprise-level content management system, provides great flexibility in content organization and display.Among them, skillfully using template tags is the key to leveraging its potential.Today, let's delve into how to use the `categoryList` tag to accurately retrieve all top-level categories under a specified content model, which is crucial for building clear website navigation, content modules, or product display pages.

2025-11-06

How to create custom fields for different content models (such as articles, products) in AnQiCMS?

Good, as an experienced website operation expert, I am very willing to deeply analyze the powerful functions and actual operations of the customized fields in AnQiCMS. --- ## In AnQiCMS, create custom fields for different content models: unlock the powerful engine of personalized content In the era where content is king, the diversity and personalization of website content are key to attracting and retaining users.A remarkable content management system (CMS) should never limit you to a fixed content structure.AnQiCMS understands this way

2025-11-06

How does AnQiCMS handle the management of pseudo-static and 301 redirection to solve the problem of URL structure optimization and traffic loss?

## AnQiCMS' Static URL and 301 Redirect: A Smart Solution for URL Optimization and Traffic Protection In the digital wave, a website's URL (Uniform Resource Locator) is far more than a simple address.It is not only the path that users access the page, but also the key clue for search engines to understand the content of the website and evaluate its value.A clear and semantically friendly URL can significantly enhance user experience, improve search engine crawling efficiency and ranking performance.

2025-11-06

How `tagList` tags display the related Tag list of the specified document?

As an experienced website operations expert, I know that how to flexibly and effectively organize and display content in a content management system is the key to improving user experience and search engine optimization (SEO).AnQiCMS (AnQi CMS) offers many powerful functions in this aspect, and the `tagList` tag is an important bridge to connect content and enhance discoverability.Today, let's delve into how to use the `tagList` tag in AnQiCMS to accurately display the associated tag list of a specified document.### Fine-grained content management

2025-11-06

How to retrieve all documents under a specific Tag and implement pagination using `tagDataList` tag?

In the vast field of content operation, tags (Tags) play a crucial role.They can not only thematize and structure scattered content, but also guide users to explore deeply, improve the efficiency of content discovery, and enhance the overall user experience of the website.As an experienced website operations expert, I am well aware of the powerful capabilities of AnqiCMS (Anqi CMS) in label management and content display.

2025-11-06

How to use the `pageDetail` tag to get detailed content and images of a single page (such as "About Us")?

In website operation, pages like "About Us" and "Contact Us" are indispensable, as they carry important information such as corporate culture, contact information, and service introduction.How to present these carefully prepared contents efficiently and beautifully on the front end of a website is a skill that every website operator needs to master.For users using AnQiCMS, the `pageDetail` tag is the key tool to achieve this goal.

2025-11-06

How to build a multi-level website navigation menu using the `navList` tag and support dynamic display of categories or document links?

As an experienced website operations expert, I am well aware of the importance of a clear and efficient website navigation system for improving user experience, guiding content consumption, and optimizing search engine rankings (SEO), which is self-evident.In AnQiCMS (AnQiCMS) such a well-designed content management system, building flexible and variable navigation menus, and making them able to intelligently display dynamic content, is the key to operators achieving fine-grained content layout.

2025-11-06