How to retrieve all **category lists and display them on the page?
Anqi CMS: How to retrieve and display all **category lists on the website page
As a website operator, I fully understand the importance of clear website structure for user experience and Search Engine Optimization (SEO).Categorization navigation is one of the core elements of website content organization, it not only guides users to quickly find the information they need, but also helps search engines better understand the content hierarchy of the website.AnQiCMS provides a直观 and powerful template tag system, allowing website operators to easily manage and display the classification structure of the website.
Understand the classification system of Anqi CMS
In AnQi CMS, content is organized in the form of 'categories'.Each category belongs to a specific "content model" (such as article model, product model), which makes content management more flexible and structured.To obtain the list of website categories, we first need to understand how these categories are associated with the content model, as it is often necessary to specify the content model ID when calling the category data.
applycategoryListTag to get category data
AnQi CMS template system provides a namedcategoryLista dedicated tag for retrieving and looping through the website's category data. This tag is designed to be very flexible and can be configured with parameters according to different needs (such as retrieving specific model categories, retrieving child categories, retrieving all categories, etc.). For our current requirement - retrieving all **category lists,categoryListThe key to the tag is itsparentIdParameter.
Accurately retrieve **category lists
To accurately retrieve all categories that do not belong to any superior categories, we need toparentIdthe parameter to"0"In addition, since each category in the AnQi CMS is bound to a specific content model, when retrieving **categories, we also need to specify the categories belonging tomoduleIdFor example, if we want to get the article model (usuallymoduleId="1"All **categories under this) will be specified, so the combined label will specifymoduleId="1"andparentId="0"Thus,categoryListThis label can accurately return the required **category data.
Display the **category list on the page
Once we pass throughcategoryListAfter the label gets the **category data, it can beforLoop to iterate through these data and display it on the page. Inside the loop, we can easily access various properties of each category, such as the category ID (item.Id), Title (item.Title) and link (item.Link) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assuming
) etc. The following is a specific template code example demonstrating how to retrieve the article model (assumingmoduleIdFor all **categories under 1), and display their titles and links in list form:
{# 假设要获取文章模型(moduleId="1")的所有**分类 #}
<nav class="main-category-navigation">
<ul>
{% categoryList categories with moduleId="1" parentId="0" %}
{% for item in categories %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
{# 如果需要,可以根据 item.HasChildren 判断是否有子分类并决定是否加载更多内容 #}
</li>
{% empty %}
<li>目前没有**分类可供显示。</li>
{% endfor %}
{% endcategoryList %}
</ul>
</nav>
In this example,categoriesIs the variable name defined for the **category list. By{{ item.Link }}and{{ item.Title }}We output the access address and display name of the classification separately.{% empty %}A block is a very practical feature that displays friendly prompt information when no category data is returned, enhancing user experience.
Integrate the code into your website template.
This code can be placed at different positions in the website template according to the design requirements. For example, if this is part of the main navigation of the website, it may be included inpartial/header.htmlorbase.htmlSuch a public template file is in order to maintain consistency across all pages. If it is a sidebar category list, it can be placed inpartial/aside.htmlEmbed it directly into the page template it needs, such asindex/index.html. No matter where it is placed,categoryListthe tag ensures that the latest category data is dynamically loaded without manual update.
The importance of the content model ID
In actual operation, please ensure thatmoduleIdThe value matches the content model ID associated with the category you want to retrieve. AnQi CMS allows users to customize content models, so different websites have different content models.moduleIdMay vary. You can view and manage the 'Content Model' in the 'Content Management' menu of the Anqi CMS backend. Specify correctly.moduleIdThis is a key step to obtain an accurate classification list.
BycategoryListLabel collaborationmoduleIdandparentId="0"Parameters, AnQi CMS provides an efficient and flexible way to retrieve and display all **categories** of a website. This method not only maintains the clarity and tidiness of the website structure but also greatly enhances the discoverability and user experience of the content. As an operations manager, I know that the ease of use of the tool is the key to improving efficiency, and AnQi CMS does a very good job in this regard.
Frequently Asked Questions (FAQ)
1. How do I know about my content model?moduleIdare?
You can log in to the Anqi CMS backend, navigate to the "Content Management" menu, and then select the "Content Model".There, you will see all the defined content models and their corresponding IDs.For example, the 'Article Model' is usually ID 1, the 'Product Model' ID 2, but custom models will have their specific IDs.Be sure to use the exact numeric ID displayed here.
2. How should I modify the code if I want to display the subcategories of a **category** at the same time?
If you want to display subcategories under a **category**, you can do so in the **category**.forit again within the loopcategoryListLabel, andparentIdparameter set to the current **category'sitem.Id. For example:{% categoryList subCategories with parentId=item.Id %},then in this newsubCategoriesloop, display subcategories. This can build a multi-level navigation structure.
3. Why is my **category list not displaying any content?
There may be several reasons. First, please checkmoduleIdHave you correctly specified the model ID of the content you want to retrieve? Secondly, confirm that there is indeed a **category in the 'Content Management' -> 'Document Category' section of the AnQi CMS backend, and that the 'Parent Category' field for these categories is empty, indicating that they are **categories themselves. Finally, make sure that your template file is saved in UTF-8 encoding format and that there are no syntax errors that prevent the tags from being parsed correctly.