Does the `categoryList` tag support limiting the number of categories returned? How to set the `limit` parameter?

Calendar 👁️ 58

As an experienced website operations expert, I know how important it is to have fine control over content display when building and optimizing a website.AnQiCMS as an efficient and flexible content management system, its powerful template tag system provides us with abundant operational space.categoryListThe function of tags in limiting the number of returned categories and how to skillfully use itlimitParameter.

Fine control: AnQiCMScategoryListThe number of tags is limited withlimitParameter details

In the organization and presentation of website content, the classification list plays a crucial role.Whether it is the main navigation, sidebar, homepage area display, or content aggregation page, we often need to display a specific number of categories instead of all categories.categoryListTags are born for this.

categoryListDoes the tag support limiting the number of returned categories?

The answer is yes, and thiscategoryListA very practical and indispensable feature in the label.By limiting the number of categories, we can not only optimize the page loading performance, reduce unnecessary database queries, but also effectively control the page layout, improve user experience, and present important category information to visitors at the first time.Imagine if your website had hundreds of categories listed at once, it would not only make the page long but also make it difficult for users to focus.limitThe value of the parameter is highlighted.

How to setlimitthe parameter?

limitThe parameter iscategoryListThe core attribute used to control the number of returned categories. Its setting method is intuitive and flexible, supporting two main modes:

  1. Basic quantity limit

    The most direct way is to go throughlimitSpecify the number of categories you want to return. For example, if you only want to display the latest 5 top-level categories in the homepage sidebar, you can set it like this:

    {% categoryList categories with moduleId="1" parentId="0" limit="5" %}
        {# 在这里循环输出您的分类列表 #}
        <ul>
        {% for category in categories %}
            <li><a href="{{ category.Link }}">{{ category.Title }}</a></li>
        {% endfor %}
        </ul>
    {% endcategoryList %}
    

    In this example,moduleId="1"Specified the category under the article model,parentId="0"This indicates fetching the top-level category, whilelimit="5"It precisely limits the returned results to the first 5 categories.

  2. "Offset Mode"

    AnQiCMS'limitParameters also support a more flexible usage, namelyoffsetPattern.This allows you to start from a certain position in the result set and retrieve how many data items.This pattern is very useful in some advanced layout or content alternation display scenarios."起始位置,数量"For example"2,10"It indicates starting from the 3rd category (starting at 0, so 2 represents the third), and getting 10 categories.

    Assuming you want to skip the first 2 categories and get the next 8 categories, you can write it like this:

    {% categoryList featuredCategories with moduleId="1" parentId="0" limit="2,8" %}
        {# 跳过前2个,从第3个开始获取8个分类 #}
        <div class="featured-sections">
        {% for category in featuredCategories %}
            <h3><a href="{{ category.Link }}">{{ category.Title }}</a></h3>
            {# 可以在此基础上展示分类的描述、缩略图等 #}
        {% endfor %}
        </div>
    {% endcategoryList %}
    

    Please note,limitAll numbers in the parameters should be integers.

tolimitUsed in conjunction with other parameters

Of course,limitParameters are usually not used in isolation. They are often used with other parameters, such asmoduleId(specifying the model it belongs to, such as the article model or the product model) andparentId(Specify the parent category ID to obtain subcategories) combined to complete accurate content filtering and quantity control.

This flexible control capability is particularly important in various operating scenarios. Whether it is to build a clear main navigation, design an attractive sidebar recommendation module, or display related categories in the content footer,limitParameters can help us present the required content in the most concise and efficient way.It ensures that the page information is moderate, and it will not appear disorganized due to too many categories, thereby enhancing the professionalism and user-friendliness of the entire website.

While usinglimitWhen setting parameters, it is recommended that you consider the actual page design and user needs.Reasonably setting the number of categories can make the website structure clearer, content easier to find, and ultimately help improve the conversion rate and user stickiness.

MastercategoryListlabel'slimitParameters, you will be able to control the presentation of website content more finely, allowing your AnQiCMS site to present a ** appearance to users.


Frequently Asked Questions (FAQ)

  1. categoryListDoes the tag support similar toarchiveListHow to paginate that? categoryListThe tag itself does not provide direct pagination functionality (for example, through)type="page"parameters). It is mainly used to get a fixed number of categories or a list under a specific parent. If you need toCategory ListPerform pagination, for example, loading categories in batches on a special topic page, which usually requires frontend JavaScript logic or switching with backend route parameters to achieve a similar effect, rather than relying onlimitParameters are directly paginated.limitIt is more used as a means of 'get the first N' or 'start from the Xth to get Y'.

  2. limitCan the parameter be used with the sorting parameter to display something like 'Top 5 Categories'?According to the AnQiCMS documentation,categoryListThe documentation for the tags does not provide it directlyorderParameters to specify the sorting method of the category (for example, by clicks or popularity).The default sorting of categories usually follows the order set in the background (via the display order field) or by ID order.limitThe parameter itself is only responsible for the truncation of quantities, not involving sorting logic.

  3. I want to display all categories, but at the same time, I want to control the number of articles displayed under each category.limitCan the parameter still be used?Of course!categoryListoflimitThe parameter is controlCategory Listthe quantity itself. And if you want to control the number of articles under each category, that will be incategoryListthe loop inside, usingarchiveListtag, set itslimitparameters. These twolimitIs applicable to data at different levels and types, without affecting each other, and can be used well together. For example:

    {% categoryList parentCategories with moduleId="1" parentId="0" %} {# 获取所有顶级分类 #}
        {% for parentCat in parentCategories %}
            <h3>{{ parentCat.Title }}</h3>
            <ul>
            {% archiveList articles under parentCat with categoryId=parentCat.Id limit="3" %} {# 在每个分类下获取3篇文章 #}
                {% for article in articles %}
                    <li><a href="{{ article.Link }}">{{ article.Title }}</a></li>
                {% endfor %}
            {% endarchiveList %}
            </ul>
        {% endfor %}
    {% endcategoryList %}
    

    Thus, you can flexibly display all top-level categories and also limit the number of articles displayed under each category.

Related articles

How to get the list of all direct subcategories of the current page category?

As an experienced website operations expert, I am well aware that how to efficiently organize and display the classification structure is crucial when managing a content-rich website.AnQiCMS (AnQiCMS) with its powerful template tag system provides us with great flexibility, making it easy to achieve various complex classification display needs.Today, let's delve into a common and practical scenario: how to obtain and display the list of all direct subcategories under the current page category.

2025-11-06

What is the specific function and application scenario when the `parentId` parameter of `categoryList` is set to "0"?

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, the `categoryList` tag is undoubtedly an important tool for building the framework of a website.Today, let's delve into the `categoryList` tag and its seemingly simple yet extraordinary parameter `parentId="0"`. What specific role and application scenarios does it have?

2025-11-06

How to implement nested display of multi-level categories in AnQiCMS templates, such as a three-level menu?

In modern web design, a clear and intuitive navigation system not only greatly enhances user experience but is also an indispensable part of search engine optimization (SEO).A multi-level classification menu, especially a three-level nested menu, can effectively organize a large amount of content, allowing users to quickly locate the information they need, and also helps search engines understand the hierarchical structure of the website.As an experienced website operations expert, I am well aware that implementing such a feature in AnQiCMS (AnQi CMS) is both simple and efficient.

2025-11-06

How to only display categories under specific content models (such as articles or products) in `categoryList`?

As an experienced website operations expert, I know that the flexibility of the Content Management System (CMS) is crucial for efficient operations.AnQiCMS (AnQiCMS) performs exceptionally well in this area with its powerful content model features.Today, let's delve into a common requirement: how to use the `categoryList` tag to accurately display only the categories under specific content models (such as articles or products).

2025-11-06

How do I correctly use the `all=true` parameter of `categoryList` to display all categories in the sidebar?

In Anqi CMS, efficiently managing and displaying website content is the key to operational success.The sidebar acts as an important navigation area for websites, often needing to display clear categories to guide users quickly to the information they need.When you want to display all categories in the sidebar and are puzzled by the `all=true` parameter of the `categoryList` tag, this is exactly the topic we will delve into today.In AnQi CMS, categories are the framework for organizing website content.

2025-11-06

What do `categoryList` loop's `item.Title` and `item.Link` represent, and how to output?

As an experienced website operations expert, I know that how to efficiently and accurately extract and display data in a content management system is the cornerstone of website success.AnQiCMS is an enterprise-level content management system based on the Go language, and its simple and efficient template engine is very appealing to me.Today, let's delve deeply into what `categoryList` loop's `item.Title` and `item.Link` represent in AnQiCMS template development, and how we can elegantly present them in the template.### Reveal

2025-11-06

How can you determine if a category has a subcategory? How can the `item.HasChildren` field be applied to conditional judgments?

As an experienced website operations expert, I deeply understand the importance of efficiently using template tags in the daily application and content strategy formulation of AnQiCMS (AnQiCMS).Today, let's delve deeply into a very practical topic in website structure construction: how to determine whether a category (Category) contains subcategories, and how to cleverly use the `item.HasChildren` field in templates to achieve intelligent content display.

2025-11-06

Can the `categoryList` tag display the number of documents under each category? How can `item.ArchiveCount` be retrieved and displayed?

As an experienced website operation expert, I know that how to efficiently and intuitively display content data in a content management system is the key to improving user experience and content operation efficiency.AnQiCMS (AnQiCMS) offers us great flexibility with its simple and efficient architecture.Today, let's delve deeply into a question that both operators and template developers are very concerned about: Can the `categoryList` tag display the number of documents under each category?How to get and display `item.ArchiveCount`?” --- ##

2025-11-06