How does AnQiCMS achieve multi-level nested category calls and document list display?

In the operational practice of AnQiCMS, flexible content organization and display is a key element in attracting and retaining users.Multi-level category nesting calls and dynamic display of document lists are the core manifestations of the powerful content management capabilities granted to operation personnel by AnQiCMS.By巧妙地运用系统模板标签,we can not only build a clear website structure, but also present content accurately according to the reader's needs.

AnQiCMS category system overview

The content management of AnQiCMS is based on 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 the document classification further categorizes specific content hierarchically on this basis.For example, under a 'Article Model', there can be 'News Dynamics', 'Technical Tutorials', 'Industry Analysis', and other first-level categories. Each first-level category can further be subdivided into second-level and third-level categories, forming a structured content system.This hierarchical organization method is crucial for user navigation, content retrieval, and SEO optimization.

Implement nested calls for multi-level classification

AnQiCMS uses its powerful template tagscategoryListmaking nested calls for multi-level classification intuitive and efficient.categoryListTags are used to retrieve the category list under the specified content model and provide rich parameters to control the call range and level.

When we need to display the navigation menu of a website, or present the category tree in the sidebar,categoryListtags can help us easily achieve this. The core lies in utilizingmoduleIddesignating the content model of the specified content, and combiningparentIdParameters are traversed hierarchically. For example, to get all top-level categories, we can setparentId="0". While traversing these top-level categories, each category itemitemAll contain aIdfield andHasChildrenfield. We can useHasChildrenTo determine if the current category has subcategories, if it does, it can be called againcategoryListand pass the current category'sIdAs a subcategoryparentId, thus realizing infinite-level nesting.

This is a typical code structure for implementing multi-level nested category 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 outer layer of.categoryListgets the top-level category, followed by.forIterate through these categories. We call again within each top-level category.categoryListUseparentId=item.IdTo get its direct subcategories. 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 links and display names for categories, ensuring the correctness of navigation and user experience.

Flexible document list display

After an完善 classification system has been established, how to efficiently display a list of documents based on these classifications is the next key step. AnQiCMS providesarchiveListTags, it is a powerful content aggregator that can filter and display documents based on various conditions.

archiveListTags can be used in conjunction with document lists to obtaincategoryIdThe parameter is used to specify that only documents under a certain or several categories should be displayed. It is worth noting that,archiveListIt also supportschildparameter, with its default value being,trueThis means it will automatically include documents from all subcategories under the current category. If the operations personnel only need to display documents from the current category itself and not include the content of its subcategories, then they canchildsetfalse.

This is an example of displaying document lists combined with category loops:

{% 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 first go through:categoryListTo get the top-level category, then in aforLoop, call for each category again:archiveList【en】At this point,archiveListofcategoryIdParameters are dynamically set to the current category'sitem.Idthereby achieving document aggregation by category display.limit="6"limits only 6 documents to be displayed under each category,type="list"indicating the regular list display.

In addition to displaying by category,archiveListit also supports various advanced filtering and sorting features to meet more complex display requirements:

  • pagination display: whentype="page"whenarchiveListwill generate pagination data, and needs to be coordinated withpaginationTag to render pagination navigation. This is especially important for displaying a large number of documents, as it can improve page loading speed and user experience.
  • recommendation attributes: UtilizingflagWe can filter documents with specific recommendation attributes (such as headlines, recommendations, sliders, etc.) to highlight them on the homepage or specific areas.
  • Sorting method:orderParameters allow us to sort by document ID, views, custom sort values, and more, ensuring content is presented in the most relevant or freshest manner.
  • Search and filter:qThe parameter can be used for title keyword search, and custom filter parameters can be passed through URL query parameters to further refine the display content of the document list, for example, by filtering according to product features or article tags.

Summary

AnQiCMS provides highly flexible multi-level nested calls and document list display capabilities for website operators through its concise and powerful template tag system.From building clear website navigation to dynamically presenting content based on细分分类, and to achieving advanced content filtering and sorting, AnQiCMS empowers content operators to create high-quality, easy-to-manage, and user-friendly website content with intuitive syntax and rich parameters.This not only improves the organization efficiency of the website content, but also provides users with a more personalized and convenient content access experience.

Frequently Asked Questions

How many levels of nested calls are supported in the multi-level classification of AnQiCMS?AnQiCMScategoryListTags theoretically support unlimited levels of nested calls. Each time a call is madecategoryList, just use the ID of the parent category asparentIdParameters are passed in, and the system can obtain the next-level subcategories.In practical applications, the depth of classification usually depends on the business logic of the website and the user experience. It is generally not recommended to have too deep levels to avoid overly complex navigation.

How to ensure that only documents of the current category are displayed in the document list, and not include the content of its subcategories?When usingarchiveListWhen getting the document list by tag, if you want to display only the documents in the current category and not include the documents in its subcategories, you can setchildparameter settingsfalse. For example:{% archiveList archives with type="list" categoryId=item.Id child=false limit="10" %}. By default,childparameter astrue,It will display all sub-category documents.

In addition to filtering by category, what flexible ways does AnQiCMS support for displaying document lists?AnQiCMSarchiveListLabel supports various flexible display methods. In addition to sorting bycategoryIdfiltering, you can alsoflagfilter documents with specific recommended attributes (such as headlines, recommendations); byorderParameter custom sorting method (such as by browsing