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.