AnQiCMS (AnQiCMS) is an efficient and flexible content management system, and its powerful template tag system is the key to content operators achieving personalized display. Among a multitude of practical tags, categoryListThe tag is undoubtedly an important tool for building the skeleton of a website. Today, let's delve into it in depth.categoryListA seemingly simple but extraordinary parameter in the tag -parentId="0"It is used to find out its specific role and application scenarios.
parentId="0"The cornerstone of the website content hierarchy.
In the Anqi CMS,categoryListTags are used to obtain the classification list of websites, such as article classification, product classification, etc., when we will.parentIdparameter settings"0"It has a very clear and core role:It indicates that the system should only return categories without parent categories, which is what we commonly refer to as the top-level categories or root categories of a website.Imagine a file system,parentId="0"As if to request listing all folders directly under the root directory, not scattered in deep subdirectories.
The design of this parameter reflects the consideration of Anqi CMS in content structural management.It provides a clear starting point, helping operators to organize and present content starting from the top-level logical structure of the website.moduleId(For example, if the article model ID is 1 and the product model ID is 2), we can accurately obtain all top-level categories under a specific content model.This top-down content hierarchy construction method is crucial for the information architecture of the website, user navigation experience, and search engine optimization.
parentId="0"the core function and wide application scenarios
parentId="0"The existence of parameters enables A safe CMS to have extremely high flexibility and controllability when building and managing the website content structure.Its core function lies in providing a clear, programmable interface for accessing the most basic categorization levels of a website.
build the main navigation menuThis is
parentId="0"The most common and most intuitive application scenario. The main navigation menu of a website usually displays the main content sections of the website, which are often top-level categories. ThroughcategoryListwithparentId="0"EnglishFor example, the main navigation of a corporate website may include "About UsWhen a new top-level category needs to be added to the main navigation, simply add the category in the background, and the front-end navigation will automatically update, greatly reducing maintenance costs.Home core content module displayOn the homepage of the website, in order to quickly guide users to discover the core content, some modules are often designed to display the main categories.For example, the "Latest Articles
parentId="0"Can quickly obtain these categories and then combinearchiveListLabel further displays the latest or recommended content under these top-level categories, forming a rich and clear layout of the homepage.SEO optimization and sitemap constructionSearch engines attach great importance to the structure of a website when crawling and understanding its content.An clear, flat top-level category structure helps search engines better understand the website theme and improve the relevance score of content.
parentId="0"The parameter makes it very easy to generate XML Sitemap for search engines or readable HTML Sitemap for users.Through listing all top-level categories, search engine spiders can more easily delve into these entry points to crawl other pages of the website, enhancing the inclusion efficiency and ranking potential of the site.Multiple site content integration and displayOne of the major advantages of Anqi CMS is that it supports multi-site management. In a multi-site environment, different sites may have independent or related content systems.
parentId="0"CombinesiteId参数,可以在一个站点中方便地获取到另一个站点下的顶级分类信息,从而实现跨站点的导航、内容推荐或内容聚合,为复杂的企业级多站点运营提供了强大的支持。
For example, if we want to display all top-level article categories as filter conditions in the article list, the template code may look like this:
<nav class="main-navigation">
<ul>
{% categoryList topArticleCategories with moduleId="1" parentId="0" %}
{% for category in topArticleCategories %}
<li><a href="{{ category.Link }}">{{ category.Title }}</a></li>
{% endfor %}
{% endcategoryList %}
</ul>
</nav>
This code will dynamically iteratemoduleIdAll top-level categories for 1 (assuming an article model), and render their titles and links in the main navigation menu of the website.
In short,categoryListthe tag inparentId="0"The parameter is a fundamental and powerful component of the safety CMS content operation strategy.It not only simplifies the process of obtaining top-level categories, but more importantly, it provides a clear starting point and an efficient implementation path for website structure, navigation design, user experience, and search engine optimization.By cleverly using this parameter, operators can build a logical, easy to manage, and user-friendly website content system.
Common Questions and Answers (FAQ)
1. Can I inparentId="0"On this basis, further obtain the subcategories of these top-level categories?Of course you can.parentId="0"After helping you obtain all the top-level categories, you can use them again in the loop to traverse these top-level categories.categoryListLabel, use the ID of the current top-level category asparentIdParameters (e.g.,)parentId=category.Id). This nested loop is a commonly used method to build multi-level navigation or hierarchical classification structures.
2. BesidesparentId="0",parentIdWhat are some common usages of the parameter?Besides setting it to"0"Besides getting the top-level category,parentId还可以设置为具体的分类ID,以获取该分类下的所有直接子分类。另外,一个常用的高级用法是设置parentId="parent"This is usually used on subcategory pages, it can retrieve the sibling categories of the current category (i.e., all categories that share the same parent level as the current category), which is convenient for displaying同级 navigation in the sidebar and other locations.
3. How can I get all top-level categories under all models, instead of getting the top-level categories for specific content models (such as articles or products)?Anqi CMS'scategoryListLabels usually need to be specified bymoduleIdparameters to specify which content model category you want to query. If you want to get all top-level categories under all models, this means you need to query each one separately.moduleIdUseparentId="0"Perform a query and merge or display the results separately. There is currently no singlecategoryList调用可以直接获取“所有模型的所有顶级分类”的功能,因为不同模型之间的分类体系是相对独立的,需要明确指定所属模型。