As an experienced website operations expert, I know that the flexibility of the Content Management System (CMS) is crucial for efficient operation.English CMS (EnglishCMS) performs exceptionally well in its powerful content model functionality.categoryListLabel, accurately displays only the specific content model (such as articles or products) under the category.
In the AnQi CMS, each content has its corresponding model, for example, the news articles on your website may belong to the "Article ModelThis design makes content management orderly.categoryListLabel, it is the powerful tool that you use to call and display these category information in the frontend template.
Understanding the content model and category association of AnQi CMS
In the Anqi CMS, the content model is like the blueprint for different types of content on your website.It defines which fields should be included, how to organize and display specific types of content (such as articles, products, news, cases, etc.).For example, the "article model
Each category is closely associated with a specific content model.This means that when you create a category, you need to specify which content model it belongs to.This design logic ensures the specificity of classified content, for example, the "Company News" category must belong to the "Article Model
It is the tight binding relationship between this model and category that allows us to identify the content model (i.e.moduleId),来精确筛选出我们想要的分类列表。
categoryList标签的核心作用与moduleIduses
categoryListTags are the key tools in Anqi CMS templates used to retrieve category lists. They provide various parameters to help you flexibly control the categories displayed, and among them, the most core and most able to meet our discussion needs today ismoduleId.
moduleIdThe parameter allows you to specify the category list you want to retrieveContent Model ID. In the background of Anqi CMS, each content model has a unique numeric ID. Usually, the “article model” ofmoduleIdThe default is1and the 'product model'moduleIdThe default is2。If you create a custom content model, they will also have corresponding IDs. You can view each model's ID in the 'Content Management' -> 'Content Model' section of the backend.
By using incategoryListsetting in the labelmoduleIdParameters, you can easily filter out categories that belong only to specific content models, avoiding mixing different types of categories together, making your website structure clearer and content display more accurate.
实战演练:一步步构建特定模型的分类列表
现在,让我们通过具体的模板代码示例,来学习如何运用moduleIdParameter.
Example one: Get all top-level categories under the article model
假设您希望在网站的导航栏或某个侧边栏中,只显示所有关于文章的顶级分类(例如“公司新闻”、“行业动态”等),并且这些分类都属于“文章模型”。
You can use the following code:
{% categoryList categories with moduleId="1" parentId="0" %}
<ul>
{% for item in categories %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
{# 这里可以根据需要,进一步展示子分类或该分类下的文档数量等信息 #}
<span>({{ item.ArchiveCount }}篇文章)</span>
</li>
{% else %}
<li>暂无文章分类。</li>
{% endfor %}
</ul>
{% endcategoryList %}
In this code block:
moduleId="1"Make it clearcategoryListTags, we only care about the categories under the content model (i.e., article model) with ID 1.parentId="0"It means we only want to get the top-level categories of these article categories.
Example two: Get the second-level categories under the product model.
If you want to display all second-level subcategories under the current category page, and these categories all belong to "product model", you can operate in this way:
{# 假设当前页面已经识别出所属的产品分类,我们想显示其下的子分类 #}
{# 首先,获取当前页面的分类ID,通常页面上下文会自动提供,这里假设为 currentCategoryId #}
{# 或者,如果您在产品列表页,可以直接使用 item.Id 来获取当前遍历的分类ID #}
{% categoryList subCategories with moduleId="2" parentId=currentCategoryId %}
<div class="product-sub-categories">
<h3>当前分类的子分类:</h3>
<ul>
{% for subItem in subCategories %}
<li>
<a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
<span> (包含{{ subItem.ArchiveCount }}款产品)</span>
</li>
{% else %}
<li>当前产品分类下暂无子分类。</li>
{% endfor %}
</ul>
</div>
{% endcategoryList %}
Here:
moduleId="2"Ensure that the category we obtain is exclusively for the product model.parentId=currentCategoryIdThen dynamically obtain the category ID of the current page and display its direct subcategories.currentCategoryId应该替换为实际的当前分类ID变量,在列表页中通常可以直接使用item.Id.
不仅仅是列表:分类信息的丰富展示
once you have passed throughmoduleIdSuccessfully filtered out the required category list, you can use it in the loopitemto enrich the display of category information with various properties, for example:
{{ item.Title }}: Display the category name.{{ item.Link }}:Generate the link for the category detail page.{{ item.Description }}:Display the brief introduction of the category.{{ item.Logo }}or{{ item.Thumb }}:Show the cover image or thumbnail of the category, suitable for categories with image needs.{{ item.ArchiveCount }}:Displays how many documents (articles, products, etc.) are under this category.{{ item.HasChildren }}:Determines whether the current category has subcategories for conditional rendering.
The flexible use of these properties can make your category list not only powerful in functionality but also beautiful in interface and rich in information, greatly enhancing the user experience.
Summary
Anqi CMS'scategoryListTag combinationmoduleIdParameters provide high flexibility for website operators, allowing precise control over the classification and display of content based on different business needs and content models.This makes your website structure clearer, greatly simplifies the complexity of template development, and improves the efficiency of content management.Master this skill, and you will be able to build a powerful and well-organized website content architecture more freely, thus better serving your users and business goals.
Common Questions (FAQ)
1. How can I determine the corresponding "article model" or "product model"?moduleIdHow much is it?
Generally speaking, the built-in "article model" of the corporate CMS ismoduleIdYes1and the 'product model'moduleIdYes2.If you want to confirm or view the ID of a custom model, please log in to the Anqi CMS backend and go to the 'Content Management' -> 'Content Model' page.Each content model will display its ID next to its name or in the URL of the detail page.
2.parentIdParameter incategoryListWhat is the function of it? How should I set it to display all categories?
parentIdThis parameter is used to specify the child categories under a specific parent category. WhenparentId="0"When, it will get all top-level categories. If you want to get all subcategories of a specific category,parentIdSet the ID of the parent category. If you want to display all categories under all models, regardless of the level, you can useall=trueparameters, such as{% categoryList categories with moduleId="1" all=true %}. But please note,all=trueIt will return all levels of categories, and you may need to handle the hierarchy display logic in the template yourself.
3. Can I use acategoryListLabel in, show categories from both "Article Model" and "Product Model" at the same time?
No,moduleIdThe parameter is for filtering a single content model. OnecategoryListOnly one label can be specified.moduleIdIf you indeed need to display categories from different content models in the same list, you need to use two (or more)categoryListtags, each specifying differentmoduleIdThen manually merge their results or process them on the frontend through JavaScript.For example, you can first get the list of article categories, then get the list of product categories, and then render or combine them separately in the template.