How to display comment content and user status for the `commentList` label in AnQiCMS?

Calendar 👁️ 63

Build a highly interactive website in AnQiCMS, and the comment feature is undoubtedly the key to increasing user engagement.commentListThe label is a great tool provided by AnQiCMS for this purpose, it can help website developers and operators flexibly display comment content, and clearly present the status of commenters, allowing visitors to grasp the dynamics of the comment area at a glance.

Overview of core features: commentListBasic usage of tags

commentListTags are mainly used to obtain the comment list of a specified document and support pagination. Its basic structure is usually like this:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 评论内容将在这里循环展示 #}
{% endcommentList %}

Here, commentsWe define the variable name for the comment list data obtained, you can name it as needed.archiveId=archive.IdSpecifies which article (or product) comments to retrieve, here thearchive.Idusually it is automatically obtained the ID of the current article on the article detail page.type="page"indicates that we want to display comments in the form of pagination, if pagination is not needed, you can usetype="list".limit="10"It controlled the number of comments displayed per page.

With such settings, we can retrieve comment data from the database to prepare for subsequent display.

A comprehensive display of comment content:itemVariable Details

commentListTags retrieved from comments.commentsA variable is an array object, each array element represents a comment, we usually iterate over these comments in a{% for item in comments %}loop. Each object contains rich comment information, for example:item.

  • Id: The unique identifier ID of the comment.
  • UserName: The nickname of the commenter.
  • Content: The actual text content of the comment.
  • CreatedTime: The timestamp of the comment post, usually needs to be{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}converted to a readable date and time by such a formatting function.
  • Status: The review status. This is a very important field, usually1indicating that the review has been approved and displayed,0Pending review.
  • ParentIdandParentobject: If the current comment is a reply to another comment,ParentIdIt will record the ID of the parent comment, andParentthe object will contain the complete information of the parent comment, convenient for implementing the display of multi-level comment replies.
  • VoteCount: The number of likes received from comments.

Master these fields, and we can build flexible and diverse comment display effects in the template.

Differentiate comment status: make it clear to the user.

In comment display, clearly inform the user whether a comment has been approved, which is very important for the operation of the website and the user experience. Usingitem.StatusField, we can easily achieve this.

For example, you can display a "Under review" prompt next to the commenter's name, or show only part of the content or a placeholder when the comment content does not pass review.

<div>
    <span>
        {% if item.Status != 1 %}
            <span style="color: gray;">[审核中]</span> {{item.UserName|truncatechars:6}}
        {% else %}
            {{item.UserName}}
        {% endif %}
    </span>
    <span>于 {{stampToDate(item.CreatedTime, "2006-01-02 15:04")}} 说:</span>
    <div>
        {% if item.Status != 1 %}
            <p style="color: gray;">您的评论正在审核中,请耐心等待。</p>
        {% else %}
            <p>{{item.Content}}</p>
        {% endif %}
    </div>
</div>

By making such a judgment, it respects the privacy of the reviewer while also clearly informing other visitors of the current status of the comment, enhancing the transparency and interactivity of the page.

Implement comment replies and like interactions

Display of comment replies

AnQiCMS'commentListTag throughitem.ParentThe object perfectly supports comment replies. Whenitem.ParentWhen present, it means that the current comment is a reply to another comment.We can use this information to display the content of the parent comment in a nested or referenced manner, thus building a clear conversation structure.

<div>
    {# 当前评论者的信息 #}
    <span>{{item.UserName}}</span>
    <span>于 {{stampToDate(item.CreatedTime, "2006-01-02 15:04")}} 说:</span>

    {# 如果是回复,显示父评论内容 #}
    {% if item.Parent %}
        <blockquote style="background-color: #f0f0f0; padding: 10px; margin-left: 20px; border-left: 3px solid #ccc;">
            <p>回复 @{{ item.Parent.UserName }}:</p>
            {% if item.Parent.Status != 1 %}
                <p style="color: gray;">[原评论正在审核中]</p>
            {% else %}
                <p>{{ item.Parent.Content|truncatechars:100 }}</p> {# 截取父评论内容避免过长 #}
            {% endif %}
        </blockquote>
    {% endif %}

    {# 当前评论内容 #}
    <p>{{item.Content}}</p>
</div>

Implementation of comment like feature

item.VoteCountThe field directly displays the number of likes on the comment. To implement the like function itself, it is usually necessary to use JavaScript on the front end and AnQiCMS provided/comment/praiseAPI interacts. When the user clicks the like button, the JS sends a POST request to the API, including the comment'sid, and the front end updates after the API is processedVoteCountdisplay.

<div class="comment-actions">
    <a href="javascript:;" class="like-button" data-comment-id="{{item.Id}}">
        赞 (<span class="vote-count">{{item.VoteCount}}</span>)
    </a>
    <a href="javascript:;" class="reply-button" data-comment-id="{{item.Id}}" data-user-name="{{item.UserName}}">回复</a>
</div>

(Front-end JS code will listen.like-buttonfor the click event, sendPOSTrequests to/comment/praise, and update elements based on the returned resultsvote-count.)

Page control for comment list

Pagination display is essential for articles with a large number of comments. WhencommentListlabel'stypethe parameter topageIt will cooperate when,paginationTags provide complete pagination functionality.

{# 评论列表循环... #}

{# 分页部分 #}
<div class="pagination-container">
    {% pagination pages with show="5" %}
        <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>
        {% if pages.PrevPage %}
            <a href="{{pages.PrevPage.Link}}">上一页</a>
        {% endif %}
        {% for pageItem in pages.Pages %}
            <a class="{% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
        {% endfor %}
        {% if pages.NextPage %}
            <a href="{{pages.NextPage.Link}}">下一页</a>
        {% endif %}
        <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">尾页</a>
    {% endpagination %}
</div>

Users can easily navigate between different comment pages and view all comments.

Integration and submission of the comment form.

Finally, in order for users to be able to post comments, an comment form needs to be integrated. This form is usually submitted to the AnQiCMS provided/comment/publishInterface. The form must include some hidden fields and user input fields:

`twig

<input type="hidden" name="archive_id" value="{% archiveDetail with name="Id" %}"> {# 当前文章ID #}
<input type="hidden" name="parent_id" id="parent-comment-id" value=""> {# 如果是回复,这里会填入父评论ID #}
<input type="hidden" name="return" value="html"> {# 期望后端返回html,也可选json #}

<div class

Related articles

How to create a multi-level category navigation and display its subcategories or related documents in AnQiCMS template?

Build flexible multi-level category navigation and content display in AnQiCMS template Effective organization of website content is crucial for providing a good user experience and improving search engine visibility.Whether it is a corporate website, product display, or self-media blog, a clear multi-level classification navigation can help users quickly find the information they need and is also conducive to search engines understanding the structure of the website.AnQiCMS as an efficient and customizable content management system provides flexible template tags, allowing us to easily implement complex multi-level classification navigation and content display. Next

2025-11-08

How to filter the document list based on category ID, model ID, or recommendation attributes for the `archiveList` tag?

In AnQiCMS, flexibly displaying content is one of the keys to building an efficient website.The `archiveList` tag is such a powerful tool that allows us to filter and display the document list of the website based on various conditions.Whether you want to display a certain type of article on a specific page, or organize information based on content type or editor's recommendations, `archiveList` can provide precise control.### Accurate positioning: Filter document list by category ID When we want to display in a certain area of the website, such as the sidebar or a special topic page

2025-11-08

How to get the global configuration information of AnQiCMS template, such as the website name and logo?

In AnQiCMS template, cleverly obtain the global configuration of the website to make your website more flexible When designing or maintaining an AnQiCMS website template, we often encounter a need: to display unified global information on each page of the website, such as the name of the website, logo, filing number, or custom contact information.Manually adding this information to each page is not only inefficient but also time-consuming and laborious to update once it needs to be changed.

2025-11-08

How does AnQiCMS increase the level of content operation automation through the timed publishing function?

Today, with the increasing emphasis on efficiency and user experience, the degree of automation in content operation is directly related to the competitiveness of the website.For many small and medium-sized enterprises and self-media operators, how to ensure high-quality, frequent, and precise targeting of content under limited human resources is a continuous challenge.AnQiCMS is an efficient and flexible content management system, and its built-in timed publishing function exactly provides strong support for solving this problem.Imagine such a scenario: You have meticulously planned marketing content for a week or even a month, including articles, product updates, and event previews.

2025-11-08

How to enable and use the captcha feature of the留言表单in AnQiCMS?

The website guestbook is a good place to interact with visitors, which brings the website closer to the users.However, without proper protection, the message board will soon be overwhelmed by various spam, malicious submissions, and even automated scripts, which not only affects the cleanliness of the website but may also consume server resources and even damage the reputation of the website.Fortunately, AnQiCMS provides a simple and effective solution: the captcha feature.

2025-11-08

How to use the `archiveFilters` tag in AnQiCMS to achieve combined filtering of document parameters?

## Mastering AnQiCMS: The Art of Using `archiveFilters` Tag for Document Parameter Combination Filtering It is crucial to provide users with accurate and efficient content search experience in content operation.Imagine if your website has a rich variety of content, but users find it difficult to quickly find the information they need. This will undoubtedly greatly affect user experience and the conversion rate of the website.

2025-11-08

How to automatically generate the breadcrumb navigation of the page in the AnQiCMS template using the `breadcrumb` tag?

When browsing websites, we often notice a path information string at the top or bottom of the page, which clearly indicates our current location, such as "Home > Category > Article Title."}This is what we commonly refer to as Breadcrumb Navigation.It not only helps users better understand the website structure and improve the browsing experience, but also has a significant value for search engine optimization (SEO).Why is breadcrumb navigation important? For users, breadcrumb navigation is like a mini-map.

2025-11-08

How to flexibly control the display quantity and style of pagination page numbers with the `pagination` tag of AnQiCMS?

When managing a content-rich website, an efficient page navigation system is crucial for enhancing user experience and search engine optimization (SEO).AnQi CMS knows this, its built-in `pagination` tag provides us with detailed control, making the website page number display both flexible and beautiful.This article will guide you to understand how to use the `pagination` tag, flexibly control the display quantity and style of pagination page numbers.

2025-11-08