How to limit the number of comments displayed per page or in total in the `commentList` tag (using the `limit` parameter)?

Calendar 👁️ 71

As an experienced website operations expert, I know that attention to detail in content management often determines the quality of user experience and page performance.Comments are an important part of website interactivity, and the rationality of their display directly affects users' perception of the content.In a system like AnQiCMS (AnQi CMS) that is efficient and flexible, how to finely control the number of comments displayed is a topic worth in-depth discussion.commentListin the taglimitThe versatility of the parameter.

Fine control of the comment stream: In AnQiCMScommentListTaglimitDeep analysis and practical application of the parameter

In AnQiCMS,commentListTags are the core tools used to retrieve and display comments from a database. They provide rich parameters to help us customize the way comments are retrieved, among whichlimitThe parameter is the key to controlling the number of comments.By properly configuring this parameter, we can not only optimize the page loading speed and improve the user experience, but also better match the overall design style of the website.

limitBasic application of parameters: Limit the total number of comments

The most direct application is throughlimitThe parameter is used to specify how many comments to display at one time in a certain area or on a certain page. If you just want to simply display the latest or most popular comments at the bottom of an article page without pagination, thenlimitParameters can be put to good use.

For example, you want to display only the latest 5 comments on the article detail page, the code can be written as follows:

{% commentList latestComments with archiveId=archive.Id type="list" order="id desc" limit="5" %}
    {% for item in latestComments %}
        <div class="comment-item">
            <p><strong>{{ item.UserName }}</strong> 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</p>
            <p>{{ item.Content }}</p>
        </div>
    {% else %}
        <p>暂无评论,快来发表您的看法吧!</p>
    {% endfor %}
{% endcommentList %}

In this code block,limit="5"Explicitly indicate that the system should only return the first 5 comments.type="list"This indicates that it is a non-paginated list, the system will directly return the specified number of comments.order="id desc"Ensure that we get the latest comments. This method is very suitable for quickly previewing comments in the page sidebar, recommended comment section, or below the main content.

limitParameter and pagination: control the number of comments per page

However, in most cases, especially for articles with a large number of comments, we tend to paginate the comments to avoid making the page too long and affecting the reading experience. At this point,limitThe parameter withtype="page"the attributes as wellpaginationThe combination of labels can bring out its true power.

Whentypethe parameter topagethen,limitThe meaning of the parameter will change to 'how many comments per page'. The system will depend on the current page number andlimitThe value automatically calculates the range of comments to be queried.

Assuming you want to display 10 comments per page and allow users to browse all comments through pagination, you can organize the code in this way:

{% commentList pagedComments with archiveId=archive.Id type="page" limit="10" order="id desc" %}
    {% for item in pagedComments %}
        <div class="comment-item">
            <p><strong>{{ item.UserName }}</strong> 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</p>
            <p>{{ item.Content }}</p>
        </div>
    {% else %}
        <p>暂无评论。</p>
    {% endfor %}
{% endcommentList %}

<div class="pagination-controls">
    {% pagination pages with show="5" %} {# show="5" 表示最多显示5个页码按钮 #}
        {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
        {% for page in pages.Pages %}
            <a class="{% if page.IsCurrent %}active{% endif %}" href="{{ page.Link }}">{{ page.Name }}</a>
        {% endfor %}
        {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
    {% endpagination %}
</div>

In this example,limit="10"It decided to load 10 comments per page andpaginationThe label is based oncommentListThe total number of comments and the number per page, automatically generating the corresponding pagination links. This combination is a practice for building standard comment list pages.

limitAdvanced usage of parameters: Offset mode

AnQiCMS'limitThe parameter also provides a more refined control method, namely the "Offset" mode.This allows you to skip the first N comments and then retrieve a specified number of comments starting from the N+1st comment.

  • Content display after 'Top Comment' or 'Featured Comment':You may have manually displayed a few particularly important comments at the top of the page, and you want the regular comment list to start after these comments.
  • A/B test or special recommendation position:Adjust the starting point of a comment area dynamically.

The syntax of the offset mode is in.limitTwo numbers are separated by a comma in the parameter:"offset,count".offsetIt represents the number of comments to skip (starting from 0),countRepresents the number of comments starting from the offset.

For example, you may want to display the latest 3 selected comments at the top of the page (without pagination), while the rest of the comments start paginating from the 4th comment, with 10 comments per page. You can do this by:

`twig

Selected Comment

{% commentList featuredComments with archiveId=archive.Id type=“list” order=“id desc” limit=“3” %}

{% for item in featuredComments %}
    <div class="comment-item featured">
        <p><strong>{{ item.UserName }}</strong> (精选) 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</p>
        <p>{{ item.Content }}</p>
    </div>
{% else %}
    <p>暂无精选评论。</p>
{% endfor %}

End Comment List

All Comments

{% commentList remainingComments with archiveId=archive.Id type=“page” order=“id desc” limit=“3,10” %} {# Skip the first 3, display 10 per page #}

{% for item in remainingComments %}
    <div class="comment-item">
        <p><strong>{{ item.UserName }}</strong> 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</p>
        <p>{{ item.Content }}</p>
    </div>
{% else %}
    <p>暂无其他评论。</p>
{% endfor %}

End Comment List

{% pagination pages with show="5" %}
    {# 分页链接,此时分页会从总评论中减去偏移量后计算

Related articles

What sorting methods does the AnQiCMS comment list support (`order` parameter), and how to sort by the latest or the most popular?

As an experienced website operations expert, I am well aware of the importance of user interaction in content management.The comment feature is an important indicator of website activity, and how efficiently and friendly these comments are displayed directly affects user experience and the spread of content.AnQiCMS as a powerful content management system also provides flexible configuration options for comment management.Today, let's delve into the sorting method of AnQiCMS comment list, especially how to display comments based on the latest release or popularity.--- ##

2025-11-06

How to configure the `commentList` tag to display comments for a specific article (`archiveId`)?

I am glad to analyze the comment management and template configuration skills of Anqi CMS for you in depth.In website content operation, comments are an important bridge connecting users to content.AnQiCMS as an efficient content management system naturally also provides powerful comment functions and flexible template tags, helping us accurately control the display of comments. Today, we will focus on a common and core requirement: **How to configure the `commentList` tag to display comments for specific articles (`archiveId`) only?

2025-11-06

In AnQiCMS, how can the `commentList` tag implement pagination for comment data?

As an experienced website operations expert, I am well aware that the comment function in a content management system not only increases user interaction but also brings vitality and richness to the website.AnQiCMS (AnQiCMS) is an efficient content management system developed based on the Go language, which provides strong comment functions while also considering the flexibility of template creation.Today, let's delve into how to elegantly implement pagination of comment data using the `commentList` tag in AnQiCMS.--- ### AnQiCMS in English

2025-11-06

How to use the AnQiCMS `commentList` tag to display comments on the frontend page?

As an experienced website operations expert, I know that an active website cannot do without user interaction, and the comment feature is an important embodiment of user participation.In AnQiCMS (AnQiCMS), integrating and displaying comments is not difficult.Today, let's delve deep into how to use the powerful `commentList` tag of AnQiCMS to elegantly present comment content on your website's frontend page, thereby enhancing user engagement and content vitality.

2025-11-06

What are the required fields on the AnQiCMS comment submission form to successfully post a comment?

In website operation, user comments are undoubtedly an important way to enhance website interactivity, accumulate community content, and obtain user feedback.For AnQiCMS users, understanding which core fields are required in the comment submission form is crucial, as this not only concerns whether the comment can be successfully published, but also directly affects user experience and the richness of website content.As an experienced website operations expert, today I will delve into the essential fields of the AnQiCMS comment submission form and the logic behind them.

2025-11-06

How to customize the input fields of the AnQiCMS comment submission form to meet specific business requirements?

## AnQi CMS comment submission form field customization: How to meet your unique business needs?Today, with the increasing refinement of digital marketing, every interactive link on the website carries the important mission of collecting user feedback and deepening user relationships.The comment section, as a place for users to directly interact with content, the flexibility of the submitted form directly affects whether we can efficiently obtain the information we need.As an experienced website operation expert, I deeply understand that AnQiCMS (AnQi Content Management System) provides strong support for small and medium-sized enterprises and content operation teams with its efficient and customizable features.

2025-11-06

How is the AnQiCMS comment like function implemented? How does the front-end trigger and update the like count?

As an experienced website operations expert, I know that user interaction is the lifeblood of a website.In AnQiCMS, the comment function is not only a platform for content exchange, but also a direct expression of users' emotional expression and recognition of content value.Today, let's delve into how AnQiCMS cleverly implements the like function for comments, as well as how the front-end page interacts with it to update the like count in real time.

2025-11-06

How to distinguish and display the comment status ('Status' field) of 'Passed Review' and 'Pending Review' in the `commentList` tag?

As a senior website operations expert, we understand that the activity and content quality of the website's comment section are crucial for user engagement and brand image building.AnQiCMS provides flexible control in comment management, and the distinction of comment status display is a very practical function in content operation.Today, let's delve into how to finely distinguish and display the comment statuses of 'Passed Review' and 'Pending Review' when using the `commentList` tag.### Understanding the `Status` of comment states

2025-11-06