As an experienced website operations expert, I know that how to flexibly display and organize content in a content management system is the key to improving user experience and SEO effects.AnQiCMS (AnQiCMS) provides a solid foundation for content operations with its efficient and customizable features.Today, let's delve deeply into the topic ofcategoryListThe core issue of the label: Does it support custom sorting rules to display the category list?

Anqi CMS category list label:categoryListOverview

In AnQi CMS,categoryListThe tag is a powerful tool that allows us to dynamically retrieve and display the list of website categories in the template.It allows us to flexibly call the classification information of articles or products according to different business scenarios, such as navigation menus, sidebar categories, home page category blocks, and so on.According to the provided document,categoryListThe basic usage of the label is usually like this:

{% categoryList categories with moduleId="1" parentId="0" %}
    {# 在这里循环输出分类信息 #}
{% endcategoryList %}

This tag supports passing throughmoduleId(Specify model ID, such as article or product),parentId(Specify parent category ID to get its subcategories, or0represents the top category),all(Get all categories),limit(Limit the number of displayed items) as well assiteIdParameters such as specifying a site in a multi-site environment are used to accurately locate the classification collection we need. These parameters undoubtedly provide convenience for the structured display of content.

Document Exploration: Where to find sorting parameters?

With doubts about the sorting rules of the category list, I carefully reviewed the detailed documentation of AnQiCMS aboutcategoryListthe detailed documentation of tags (tag-/anqiapi-category/151.htmlanddesign-tag.md)。It is noteworthy that in both of these concerningcategoryListThe description of the tag parameters does not explicitly mentionorderorsortThis parameter allows developers to directly specify the sorting rules of the category list at the template level, for example, in descending order by ID, in alphabetical order by name, etc.

This contrasts sharply with AnQiCMS'sarchiveListtags (used in document lists) clearly provideorderParameters, support sorting according to rules such as 'id desc' (latest documents), 'views desc' (most viewed), or 'sort desc' (custom sorting by backend) and so on.This indicates that AnQiCMS has differentiated sorting control methods for different types of lists during design.

Deep understanding of the classification and sorting mechanism: the control of the background 'display order'

ThoughcategoryListThe tag itself does not provide sorting parameters at the template level, but it does not mean that the category list is random or uncontrollable. In the AnQiCMS backend management interface, there is an important configuration item for each category - 'Display Order' (help-content-category.mdMentioned in the document. It is explicitly stated that the display order can determine the sorting of this category, the smaller the number, the earlier the display. The default value when created is 99.

This means that AnQiCMS mainly puts the sorting control of the category list onthe background management level. When we create or edit categories in the background, by setting a numeric value, we can determine the display position of the category among all同级 categories. The system callscategoryListWhen a label is displayed, it will default to the display order set by the background.This is a 'what you see is what you get' management style, which is more intuitive and easy to operate for non-technical personnel.

Adaptability: When the default sorting does not meet the needs

If the display order in the background cannot fully meet your specific needs on the front end, for example, if you want the same category list to have different sorting logic on different pages, or if you need to implement some dynamic, user-interactive sorting functions, we can consider the following strategies:

  1. Priority: Adjust the display order in the backgroundThis is the most direct and the original solution of AnQiCMS.For the vast majority of static sorting needs, simply log in to the backend, go to "Content Management" -> "Document Categories", edit the corresponding category, and adjust the "Display Order" value to an appropriate position.For example, if you want a category to always be at the top, you can set its display order to 0 or 1, ensuring that its value is less than that of other categories.This method is simple and effective, and it is SEO-friendly because it changes the default output order of categories.

  2. Custom sorting in front-end JavaScript (for specific scenarios)If your requirement is to implement someDynamic, interactiveThe sorting (for example, sorting by name when the user clicks the button, sorting by the most recent published, etc.), and these sorting logic does not need to be perceived by search engines, can be implemented through front-end JavaScript.

    • Steps:UsecategoryListThe label retrieves all categorized data to the front end (without concerning its initial order), and then uses JavaScript (such as Vue, React, or jQuery, etc.) to retrieve these DOM elements or data arrays and rearrange and render them according to the preset JavaScript sorting logic.
    • Consider:The disadvantage of this method is that it increases the complexity of the front-end, and since sorting occurs on the client side, search engine spiders may not be able to recognize the order of the dynamically sorted content, which is of limited help to SEO.
  3. Seek expansion or custom development (ultimate solution)For complex and deep-level sorting requirements, such as needing to sort based on the number of articles under a category, the value of a custom field, and requiring this sorting to beGenerated on the server and visible to SEOIf so, you may need to consider the secondary development of AnQiCMS or request official technical support. Modular design of Go language (AnQiCMS 项目优势.mdMentioned provides the possibility for this customization. This usually involves modifying the underlying data query logic or writing new template tags to meet specific sorting parameters.

Summary

In general, looking at AnQiCMS'scategoryListtags are not provided directly at the template levelorderorsortSpecify the sorting rules for the category list. Its core sorting mechanism depends on the "display order" field set in the background category management.This design philosophy simplifies the work of template developers, handing over most of the non-dynamic sorting control to content managers.For more advanced or dynamic sorting requirements, we can supplement with frontend JavaScript or consider customized development solutions when necessary.Understanding this mechanism can help us better utilize the existing functions of AnQiCMS and make good plans for future expansion.


Frequently Asked Questions (FAQ)

  1. Q:categoryListCan tags be likearchiveListdirectly specify the sorting method of the category through parameters? A:According to the official documentation of AnQiCMS,categoryListtags are currentlyDoes not support directlylikearchiveListsuch in the label throughorderorsortThe parameter specifies the sorting method for the category list. The default sorting of the category list is mainly determined by the "display order" field set for each category in the background management interface.

  2. Q: Have I set the display order value for categories in the background, and will the front-end category list be sorted immediately according to my settings? A:Will do. After you set the 'display order' for categories in the AnQiCMS backend, the system will use these numbers as the sorting basis by default.The smaller the number, the higher the position of the category in the list. If the front-end does not update immediately, please try to clear the AnQiCMS system cache or browser cache to ensure that the latest data is loaded.

  3. Q: How do I implement random sorting of a category list? A:AnQiCMS'categoryListThe tag itself does not provide the function of random sorting. To implement random sorting of category lists, you need to use front-end JavaScript. First, usecategoryListTag to get all category data, then write code in JavaScript to randomly shuffle the obtained category array, and finally render the sorted categories back to the page.Please note that this front-end random sorting is invisible to search engines and does not affect SEO rankings.