AnQiCMS (AnQiCMS) is an efficient and flexible content management system, whose powerful template tag system is the key to content operators achieving personalized display. Among many practical tags, categoryListTags are 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 tags -parentId="0"What is its specific role and application scenario.
parentId="0": The cornerstone of the website content hierarchy.
In AnQi CMS,categoryListThe tag is used to obtain the classification list of the website, such as article classification, product classification, etc. When we willparentIdthe parameter to"0"At that time, its role is very clear and core:It indicates that the system should only return those categories without parent categories, which is what we usually call the top-level categories or root categories of a website.Imagine a file system,parentId="0"It's like asking to list all the folders directly under the root directory, not scattered files in deep subdirectories.
The design of this parameter reflects the consideration of AnQi CMS in content structural management.It provided a clear starting point, helping operators to start organizing and presenting content from the top-level logical structure of the website.Through specifyingmoduleIdFor example, 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 websites, user navigation experience, and search engine optimization.
parentId="0"The core function and extensive application scenarios
parentId="0"The existence of parameters enables AnQi CMS to have high flexibility and controllability in constructing and managing the structure of website content.Its core function lies in providing a clear, programmable interface for accessing the most basic classification levels of a website.
Build the main navigation menuThis is
parentId="0"The most common and 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. ThroughcategoryListcooperateparentId="0",The operator can easily dynamically generate the main navigation links. For example, the main navigation of a corporate website may include "About Us", "News Center", "Products & Services", "Contact Us", etc., among which "News Center" and "Products & Services" are likely to be the top-level categories under the article model and product model.When a new top-level category needs to be added to the main navigation, it is only necessary to 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, modules are often designed to display the main categories.For example, the 'Latest Articles' module may need to list top-level categories such as news, industry trends, or the 'Hot Products' module may need to display top-level categories for different product lines. Using
parentId="0"Can quickly obtain these categories and combine themarchiveListFurther display these top-level categories with the latest or recommended content, forming a rich and clear layout homepage.SEO Optimization and Sitemap ConstructionSearch engines pay great attention to the structure of websites when crawling and understanding content.A clear and flat top-level category structure helps search engines better understand the theme of the website and improve the relevance score of the content.
parentId="0"The parameter makes it very simple to generate an XML Sitemap for search engines or a user-readable HTML Sitemap.By listing all top-level categories, search engine spiders can more easily crawl other pages of the site from these entry points, improving the website's inclusion efficiency and ranking potential.Multi-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"CombinesiteIdParameters can be easily retrieved from one site to obtain the top-level category information under another site, thus realizing cross-site navigation, content recommendation, or content aggregation, providing strong support for complex enterprise-level multi-site operations.
For example, if we want to display all top-level article categories as filtering 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 iterate overmoduleIdFor all top-level categories of 1 (assuming it is an article model) and render their titles and links to the main navigation menu of the website.
In summary,categoryListin the labelparentId="0"The parameter is a fundamental and powerful component of the Anqi CMS content operation strategy.It not only simplifies the process of obtaining the top-level classification, but more importantly, it provides a clear starting point and an efficient implementation path for website structuring, navigation design, user experience, and search engine optimization.By skillfully using this parameter, the operator can build a logically rigorous, easy to manage, and user-friendly website content system.
Frequently Asked Questions (FAQ)
1. Can I inparentId="0"Based on this, further obtain the child categories 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 that traverses these top-level categories.categoryListLabel, use the ID of the current top-level category asparentIdParameters (for exampleparentId=category.Id), to obtain its subordinate subcategories. This nested loop is a commonly used method to build multi-level navigation or tree-like classification structures.
2. BesidesparentId="0",parentIdWhat are other common usages of the parameter?Besides setting to"0"Besides getting the top-level category,parentIdCan be set to a specific category ID to retrieve all direct subcategories under that category. Additionally, a commonly used advanced feature is to setparentId="parent"This is usually used on the subcategory page, it can get the sibling categories of the current category (i.e., all categories with the same parent level as the current category), which is convenient for displaying同级 navigation in the sidebar and other locations.
3. How can I retrieve all top-level categories under all models instead of specific content models (such as articles or products)?Of Security CMScategoryListLabels usually need to be specified throughmoduleIdparameters 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 handle each one separatelymoduleIdUseparentId="0"Perform a query and display the results merged or separately. There is no single one at present.categoryListThe function can directly retrieve the 'all top-level categories of all models' because the classification systems of different models are relatively independent and it is necessary to specify the model to which it belongs.