How does AnQiCMS implement multi-level category nesting calls and document list display?
In the operation practice of AnQiCMS, flexible content organization and display is the key to attracting and retaining users.The multi-level category nesting call and dynamic display of document lists are the core embodiment of AnQiCMS giving operation personnel strong content management capabilities.By skillfully applying system template tags, we can not only build a clear website structure, but also present content accurately according to the reader's needs.
AnQiCMS classification system overview
The foundation of AnQiCMS content management lies in its flexible 'content model' and 'document classification'.The content model allows us to customize the content structure based on business needs (such as articles, products, etc.), and document classification is based on this, classifying specific content hierarchically.For example, a 'article model' can have 'news dynamics', 'technical tutorials', 'industry analysis', and other first-level categories. Each first-level category can further subdivide into second-level and third-level categories, forming a structured content system.This hierarchical organization is crucial for user navigation, content retrieval, and SEO optimization.
Implement nested hierarchical classification
AnQiCMS through its powerful template tagscategoryListmaking nested hierarchical classification intuitive and efficient.categoryListThe tag is used to retrieve the category list under the specified content model and provides rich parameters to control the call range and level.
When we need to display the navigation menu of a website or present a category tree in the sidebar,categoryListtags can help us easily achieve this. Its core lies in usingmoduleIdspecifying the content model that belongs to, and combining withparentIdThe parameter performs hierarchical traversal. For example, to get all top-level categories, we can setparentId="0". While traversing these top-level categories, each category item (item) contains aIdandHasChildrenField. We can utilizeHasChildrento determine if the current category has subcategories, if it does, then we can call it againcategoryListand use the current category'sIdas the subcategory'sparentIdThus, it can achieve infinite-level nesting.
The following is a typical code structure for implementing multi-level classification nesting calls:
{% categoryList categories with moduleId="1" parentId="0" %}
{# 这是一个一级分类的无序列表 #}
<ul>
{% for item in categories %}
<li>
<a href="{{ item.Link }}">{{item.Title}}</a>
<div>
{% categoryList subCategories with parentId=item.Id %}
{# 这是二级分类的无序列表 #}
<ul>
{% for inner1 in subCategories %}
<li>
<a href="{{ inner1.Link }}">{{inner1.Title}}</a>
<div>
{% categoryList subCategories2 with parentId=inner1.Id %}
{# 这是三级分类的无序列表 #}
<ul>
{% for inner2 in subCategories2 %}
<li>
<a href="{{ inner2.Link }}">{{inner2.Title}}</a>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
</div>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
</div>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
In this code, the outermostcategoryListto get the top-level classification, followed by theforLoop through these categories. We call again within each top-level category.categoryList, usingparentId=item.IdTo get its direct subcategory. This process can be recursively nested according to the actual classification depth of the website, thus building a complete classification tree structure.item.Linkanditem.TitleUsed to generate category links and display names, ensuring the correctness of navigation and user experience.
Flexible document list display
After building a perfect classification system, how to efficiently display the document list based on these classifications is the key step. AnQiCMS providesarchiveListTag, it is a powerful content aggregator that can filter and display documents based on various conditions.
archiveListThe tag can be used in conjunction with document list retrieval.categoryIdParameters to specify only documents under a certain or several categories. It is worth noting that,archiveListit also supportschildparameter, whose default value istrueThis means it will automatically include all documents in the subcategories of the current category. If the operator only needs to display the documents of the current category itself and not include the content of its subcategories, then it canchildis set tofalse.
Here is an example of displaying a document list combined with category looping:
{% categoryList categories with moduleId="1" parentId="0" %}
<div>
{% for item in categories %}
<div>
<h3><a href="{{ item.Link }}">{{item.Title}}</a></h3>
<ul>
{% archiveList archives with type="list" categoryId=item.Id limit="6" %}
{% for archive in archives %}
<li>
<a href="{{archive.Link}}">
<h5>{{archive.Title}}</h5>
<div>{{archive.Description}}</div>
<div>
<span>{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
<span>{{archive.Views}} 阅读</span>
</div>
</a>
{% if archive.Thumb %}
<a href="{{archive.Link}}">
<img alt="{{archive.Title}}" src="{{archive.Thumb}}">
</a>
{% endif %}
</li>
{% empty %}
<li>
该分类下暂无内容
</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
{% endfor %}
</div>
{% endcategoryList %}
In this example, we firstcategoryListGet the top-level category, and then in aforLoop, call for each category againarchiveList. At this point,archiveListofcategoryIdThe parameter is dynamically set to the current category'sitem.Idthereby achieving document aggregation display by category.limit="6"which limits each category to display only 6 documents,type="list"indicating a regular list display.
In addition to displaying by category,archiveListit also supports various advanced filtering and sorting features to meet more complex display requirements:
- page display:When
type="page"then,archiveListit will generate page data, which needs to be配合paginationLabel to render pagination navigation. This is particularly important for displaying a large number of documents, as it can improve page loading speed and user experience. - Recommended attributeUtilize
flagParameters, we can filter out documents with specific recommendation attributes (such as headlines, recommendations, slides, etc.) for easy highlighting on the homepage or in specific areas. - Sorting method:
orderParameters allow us to sort in ascending or descending order based on document ID, views, and custom sorting values, ensuring that content is presented in the most relevant or most recent manner. - Search and filter:
qParameters can be used for keyword search in the title, and custom filter parameters can be passed through URL query parameters to further refine the display content of the document list, for example, based on product features or article tags.
Summary
AnQiCMS provides a concise and powerful template tag system, offering highly flexible multi-level nested calls and document list display capabilities for website operators.From building clear website navigation to dynamically presenting content based on细分 categories, to achieving advanced content filtering and sorting, AnQiCMS empowers content operators to create high-quality, easy-to-manage, and excellent user experience website content with intuitive syntax and rich parameters.This has improved the organization efficiency of the website content, and also provided users with a more personalized and convenient content access experience.
Frequently Asked Questions
How many levels of nested category calls are supported in AnQiCMS?AnQiCMS'categoryListLabels theoretically support unlimited level category nested calls. Each callcategoryListWhen, just use the parent category's ID asparentIdThe system can obtain the sub-categories of the next level by passing the parameters.In practice, the depth of category levels is usually determined by the business logic and user experience of the website, and it is generally not recommended to have too deep levels to avoid overly complex navigation.
How to ensure that only the documents of the current category are displayed in the document list, and not the content of its subcategories?While usingarchiveListLabel to retrieve document list, if you want to display only the documents in the current category and not include the documents in the subcategories, you canchildthe parameter tofalse. For example:{% archiveList archives with type="list" categoryId=item.Id child=false limit="10" %}. By default,childparameters fortrueIt will display all the documents of the sub-categories.
Besides filtering by category, what flexible ways does AnQiCMS support for displaying document lists?AnQiCMS'archiveListTags support various flexible display methods. In addition to filtering bycategoryIdYou can also filter byflagdocuments with specific recommended attributes (such as headline, recommendation) throughorderCustom parameter sorting method (such as by browsing