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

Calendar 👁️ 71

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 manifestation of a website's 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 in comment management.Today, let's delve into the sorting method of the AnQiCMS comment list, especially how to display comments based on the latest release or popularity.


AnQiCMS comment list sorting strategy: easily master the display of the latest and most popular comments

The display and sorting of the comment list in AnQiCMS are mainly achieved through template tagscommentListControl. This tag is powerful and can help us flexibly extract comment data from the database and display it according to our needs. Understand its core parameters, especiallyorderThe parameter is the key to controlling the display of the comment list.

commentListBasic usage of tags

First, let's take a look backcommentListThe basic structure of the tag. It is usually used to specify which document's comments to retrieve (viaarchiveIdthe parameter), as well as how to display the list (typeThe parameter can bepagePage through, orlistGet a fixed number).

For example, to get the comment list of the current article, we can use it like this:

{% commentList comments with archiveId=archive.Id type="list" limit="10" %}
    {# 在这里循环展示每条评论的详细信息 #}
{% endcommentList %}

Herearchive.IdIt is usually the ID of the article (document) displayed on the current page.

Core sorting parameter (order) Explanation

What truly determines the display order of the comment list isorderParameter. This parameter allows us to specify the sorting rule of comment data.

1. Sort by the most recent comments (order="id desc")

In AnQiCMS, it is very direct to implement the sorting by 'latest comments'. Comments in the database usually have an auto-incrementingid(unique identifier), thisidIt will increase with the release of comments. Therefore,orderthe parameter toid descthis can achieve reverse sorting by ID, thus naturally presenting the latest released comments.

descIndicates descending order (from largest to smallest), so comments with larger IDs (i.e., published later) will be listed first.

How to practice: Sort by latest comments

You just need tocommentListthe tag withorder="id desc"can easily be implemented to sort by the latest.

{# 假设 archive.Id 是当前文章的ID,limit 设置为每页显示10条评论 #}
{% commentList comments with archiveId=archive.Id type="page" limit="10" order="id desc" %}
    {% for item in comments %}
    <div class="comment-item">
        <span class="comment-user">{{item.UserName}}</span>
        <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
        {% if item.Parent %} {# 判断是否有父级评论,即是否为回复 #}
        <blockquote class="reply-to">回复 {{item.Parent.UserName}}: {{item.Parent.Content|truncatechars:50}}</blockquote>
        {% endif %}
        <p class="comment-content">{{item.Content}}</p>
        <div class="comment-actions">
            <span>点赞数: {{item.VoteCount}}</span>
            {# 更多操作,如回复按钮等 #}
        </div>
    </div>
    {% else %}
    <p>暂无评论,快来发表您的看法吧!</p>
    {% endfor %}
{% endcommentList %}

{# 如果 type="page",记得配合分页标签使用 #}
{% pagination pages with show="5" %}
    <div class="pagination-controls">
        {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
        {% for p in pages.Pages %}<a href="{{p.Link}}" class="{% if p.IsCurrent %}active{% endif %}">{{p.Name}}</a>{% endfor %}
        {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
    </div>
{% endpagination %}

This code will retrieve comments under the current article ID, sorted by the latest publish time in reverse order, and supports pagination display.

2. Regarding the consideration of "Hot Comments" sorting

in AnQiCMS'scommentListlabel'sorderIn the parameters,No direct sorting option named “hot” or “popular” is providedFor example, based on likes (VoteCountThe function to sortVoteCountfield means that the number of likes of each comment can be obtained, but thisorderparameter is mainly used foridSorting of common fields.

This means that if you want to implement a strict 'most popular comments' sorting (i.e., completely according toVoteCountYou may need to take some measures to sort from high to low.Additional Measures:

  • Front-end JavaScript Sorting (for a small number of comments): If you have a small number of comments, you can go throughcommentListAfter the tag retrieves all comment data, it uses JavaScript for secondary sorting on the browser side.This does not apply to situations with a large number of comments because it will increase the front-end load.
  • Custom Development or API Integration: For situations with a large number of comments and a strong demand for 'Hot' sorting, it is more recommended to use custom AnQiCMS extension points or call custom APIs to obtain pre-sorted comment data.This usually involves deeper development work.

For the operation of a regular website, the sorting of 'Latest Comments' usually meets the needs of most users to view and participate in discussions. If 'Hottest Comments' is your

Related articles

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

How to truncate long category names in the `categoryList` loop and add an ellipsis?

## Enterprise CMS Template Tips: Gracefully truncate long category names and add ellipsis In website operation, the display of category names may seem trivial, but it actually has a significant impact on user experience and page aesthetics.A well-designed website ensures that all its elements can coexist harmoniously, especially the navigation and text in the list.When the category name is too long, it may cause layout confusion, text overflow, and even poor display on different devices, seriously affecting the user's reading experience

2025-11-06

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

As an experienced website operations expert, I know that paying attention to details often determines the quality of user experience and page performance.Comments as an important part of website interactivity directly affect users' perception of content through the rationality of their display methods.In a system like AnQiCMS (安企CMS) that is efficient and flexible, how to finely control the number of comments displayed is a topic worth in-depth discussion.Today, let's talk about the妙用 of the `limit` parameter in the `commentList` tag.

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