How to get the classification list under a specific content model (such as articles, products)?

Calendar 👁️ 63

As an experienced CMS website operation personnel, I am well aware of the importance of content organization and user experience for the success of the website.Accurately display content categories, which can not only help users quickly find the information they are interested in, but also improve the overall SEO performance of the website.Today, we will delve into how to obtain the category list under specific content models (such as articles, products) in AnQiCMS, which is crucial for building clear website navigation, content aggregation modules, and special pages.

Understand the content model and classification system of AnQiCMS

AnQiCMS provides great flexibility in content management, one of its core features is the 'flexible content model'.This means you can customize content types according to your business needs, for example, in addition to the default article and product models, you can also create various models such as events and cases.This content model is the fundamental structure of your website content.

The content model is closely associated with the classification system.In AnQiCMS, each category clearly belongs to one and only one content model.This means that when you create a "newsThis design ensures the high organization of content, avoids confusion in the classification of different types of content, and makes content management and frontend display clearer and more efficient.

UtilizecategoryListTag to get the classification list

In AnQiCMS template design,categoryListtags are the core tools for obtaining category lists. It allows you to filter and sort categories based on various conditions, one of the most critical parameters beingmoduleIdIt allows you to accurately specify which content model category to retrieve.

To usecategoryListTag, you need to call it in the template file in the following basic format:

{% categoryList 变量名称 with moduleId="模型ID" %}
    {# 循环输出分类数据 #}
    {% for item in 变量名称 %}
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    {% endfor %}
{% endcategoryList %}

here,变量名称Is the arbitrary name you specify for the category list obtained, for examplecategories.moduleIdThe parameter is used to specify the content model ID you want to obtain for the category list.

Determine the content model ID

In AnQiCMS, each content model has a unique numeric ID. Typically, the ID for the 'Article Model' is set to default as1,“Product Model” is set to default as2This may vary depending on your system configuration or the creation order of the custom model.

To accurately obtain the ID of your content model, you need to log in to the AnQiCMS admin interface.In the 'Content Management' section, find the 'Content Model' menu.After entering this page, you will see all the defined content models and their details, usually including their IDs.Record the corresponding ID of the "article" or "product" model you need to query, so that it can be used in template tags.1thenmoduleIdThe value of the parameter should be set to"1".

Actual application: Get the list of articles and product categories

MasteredmoduleIdAfter the usage, getting the classification list of a specific content model becomes very direct.

Get the classification list under the article model.

Assuming your "article" model ID is1And you want to display the top-level category (i.e., categories without a parent category), you can call it like this in the template:

<div class="article-categories">
    <h3>文章分类</h3>
    <ul>
        {% categoryList articleCategories with moduleId="1" parentId="0" %}
            {% for category in articleCategories %}
                <li><a href="{{ category.Link }}">{{ category.Title }}</a></li>
            {% endfor %}
        {% endcategoryList %}
    </ul>
</div>

This code will iterate through all top-level categories belonging to the article model and display their names and links in an unordered list.parentId="0"The function here is to limit only the top-level categories without any parent category displayed.

Get the category list under the product model

Similarly, if the ID of your "product" model is2You want to get all categories (including subcategories) under it? Then you can do it like this:

<div class="product-categories">
    <h3>产品分类</h3>
    <ul>
        {% categoryList productCategories with moduleId="2" all=true %}
            {% for category in productCategories %}
                <li><a href="{{ category.Link }}">{{ category.Spacer | safe }}{{ category.Title }}</a></li>
            {% endfor %}
        {% endcategoryList %}
    </ul>
</div>

Here, all=trueParameter indicationcategoryListTags get all categories under the specified model, not just top-level categories.{{ category.Spacer | safe }}Used to add indentation before categories with hierarchical relationships to visually distinguish parent-child categories.

Build hierarchical navigation by combining parent category parameters.

exceptmoduleId,categoryListTags also supportparentIdParameters, which is very useful for building multi-level category navigation. You can first get the top-level categories, and then call inside the loop of each top-level category againcategoryListto get its subcategories.

<nav class="main-navigation">
    {% categoryList topLevelCategories with moduleId="1" parentId="0" %}
        <ul>
            {% for topCat in topLevelCategories %}
                <li>
                    <a href="{{ topCat.Link }}">{{ topCat.Title }}</a>
                    {% if topCat.HasChildren %}
                        <ul class="sub-categories">
                            {% categoryList subCategories with parentId=topCat.Id %}
                                {% for subCat in subCategories %}
                                    <li><a href="{{ subCat.Link }}">{{ subCat.Spacer | safe }}{{ subCat.Title }}</a></li>
                                {% endfor %}
                            {% endcategoryList %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
    {% endcategoryList %}
</nav>

This code first retrieves all top-level categories under the article model. For each top-level category, if it contains subcategories (viatopCat.HasChildrenjudgment), it will call againcategoryListSet the ID of the current top-level category asparentIdTo retrieve and display its direct subcategories.

The thoughts and **practice of operation personnel

As a website operator, effectively utilizing these tags can greatly simplify the maintenance work of the website.For example, when you need to update the website navigation or display the classification of a product series on a specific page, there is no need to manually modify the HTML. Simply adjust the classification structure in the AnQiCMS backend, and the front-end page will automatically update.

We recommend that you plan the corresponding relationships between various content models and categories at the beginning of template development, and clearly name the categories in the background, so that you can quickly locate the requiredcategoryListtags when neededmoduleIdandparentIdAt the same time, by utilizing the modular design of AnQiCMS, the commonly used category list code is encapsulated in local templates, throughincludeLabel reuse can further improve development efficiency and code maintainability.

In summary, AnQiCMS providescategoryListtags and theirmoduleIdParameters are a powerful tool for website operators and template developers to efficiently manage and display specific content model categories.By using it flexibly, you can build a clear and user-friendly content display interface, thereby enhancing your website's performance in content marketing and user experience.


Frequently Asked Questions (FAQ)

1. How can I find the specific content model in the AnQiCMS backend?moduleId?

To find the ID of a specific content model, you can log in to the AnQiCMS backend and navigate to the 'Content Management' menu under the 'Content Model' page.On this page, the system lists all created or built-in content models, usually each model has a corresponding numeric ID.1The 'product model' is usually2If the ID cannot be seen directly, you can try clicking to edit a model, the URL may contain its ID, or it may be explicitly marked on the system interface.

2. Can I display categories from different content models in the samecategoryListtag? The design of the tag is for categorization of a single content model, so you cannot display categories from different content models in the same

categoryListtag in the samecategoryListSpecify multiple tags directlymoduleIdTo get a mixed classification. If you need to display classifications from different content models, you should call each content model separately.categoryListLabel, then combine or display their results independently in the front-end template.

3. How can I ensure that the category list I get only contains categories with content?

categoryListThe label itself does not provide parameters for directly filtering out empty categories. If you want to display only categories containing documents, you canforuseitem.ArchiveCountattributes to make judgments.ArchiveCountRepresents the number of documents associated with the category. For example:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for category in categories %}
        {% if category.ArchiveCount > 0 %}
            <li><a href="{{ category.Link }}">{{ category.Title }} ({{ category.ArchiveCount }})</a></li>
        {% endif %}
    {% endfor %}
{% endcategoryList %}

This code ensures that the category will only be displayed if the number of documents in the category is greater than 0.

Related articles

How to correctly generate and display breadcrumb navigation on a page?

As an experienced CMS website operation person in an enterprise, I am very clear about the importance of breadcrumb navigation in improving user experience and website SEO.It not only helps visitors clearly understand their position on the website, but also guides search engines to better understand the website's hierarchical structure.In AnQi CMS, correctly generating and displaying breadcrumb navigation is a fundamental and important content management task.

2025-11-06

How to display a website navigation menu and support multi-level dropdown navigation?

As an experienced CMS website operation personnel of an enterprise, I know that a well-organized and easy-to-use navigation menu is crucial for the website user experience and content discovery.AnQi CMS provides a powerful and flexible navigation management function, which can help us easily set up the main menu of the website and also support multi-level dropdown navigation to meet the needs of complex website structures. ### Backend Navigation Configuration: Build Menu Structure The setting of the navigation menu in AnQi CMS starts from the backend management interface.

2025-11-06

How to dynamically set and call the SEO title, keywords, and description (TDK) of the current page in the template?

As an experienced CMS website operation personnel in a cybersecurity company, I am well aware that high-quality content and excellent search engine optimization (SEO) are the foundation of a website's success.Among them, the SEO title (Title), keywords (Keywords), and description (Description) of the page, abbreviated as TDK, play a vital role.They are not only the key for search engines to understand the content of a page, but also an important factor in attracting users to click.In Anqi CMS, we have flexible and powerful mechanisms to dynamically set and call these TDK information

2025-11-06

How to obtain and display the contact information, phone number, email, WeChat, and other contact methods set in the background?

Hello, as an experienced CMS operation person in the security industry, I know that clear and convenient contact information on the website is crucial for user experience and business conversion.Today, let's discuss in detail how to configure contact information in the Anqi CMS backend and display it flexibly and accurately on various positions of the website front-end. Configure website contact information: Back-end operation guide Managing website contact information in AnQi CMS is an intuitive and powerful process.First, we need to enter the background management interface for configuration.

2025-11-06

How to retrieve detailed information for a specified category, such as the category name, description, and link?

As an experienced website content expert in AnQiCMS (AnQiCMS) operation, I fully understand the importance of classification information in building website structure and improving user experience.The Anqi CMS, with its intuitive and powerful template tag system, makes it exceptionally easy to obtain and display detailed information about categories.In order to optimize navigation, enrich page content, or improve SEO effect, accurately obtaining the category name, description, and link is an indispensable part of our daily operation.

2025-11-06

How to get the list of all single-page lists of a website?

As an experienced CMS website operation personnel of an enterprise, I know the importance of acquiring and managing website content, especially for single pages carrying core information such as 'About Us', 'Contact Information', or 'Terms of Service'.In AnQi CMS, the system provides an efficient and flexible way to obtain the list of these single pages, so that we can integrate them into website navigation, site map, or other display locations.

2025-11-06

How to get and display the title, content, and link of a specific single-page?

As an experienced CMS website operation person, I know that content is the soul of the website, and how to efficiently and accurately display content is a crucial link in our daily work.In Anqi CMS, a single page usually carries the core information of the company introduction, contact information, service description, etc., and its content often needs to be specifically retrieved and displayed in various corners of the website.Today, let's discuss in detail how to obtain and display the title, content, and link of a specific single page in Anqi CMS.

2025-11-06

How to get the list of the latest published or articles/products under a specified category?

As an experienced AnQiCMS (AnQiCMS) website operator, I am well aware of the importance of content presentation for website user experience and the effectiveness of content marketing.AnQi CMS provides a powerful and flexible template tag system that allows us to easily retrieve and display various types of articles and product lists, whether it is for the latest content updates or for special topic displays under specific categories, all can be achieved through simple configuration.

2025-11-06