How does the comment function of AnQi CMS display comment lists and reply levels?

Calendar 👁️ 70

AnQiCMS (AnQiCMS) as an efficient and flexible content management system, provides rich content display capabilities while also offering a comprehensive comment function for user interaction.Understand how to effectively display comment lists, especially dealing with multi-level replies, is crucial for enhancing website user engagement and content depth.

Implementation basis of AnQiCMS comment function

In AnQiCMS, the comment feature is an important part of website content interaction.The system is not only built-in with support for comments on articles, products, and other content, but also provides a powerful backend management interface, allowing website operators to easily review, manage, and respond to user comments.All comments are displayed through flexible template tags, which means we can highly customize the appearance and interaction of the comment area according to the design requirements of the website.

Core: The call and display of the comment list

AnQiCMS provides to display comments on the website pagecommentListTemplate tag. This tag is the core of the comment feature, allowing us to retrieve the comment data of a specified article and control its display style.

For example, on an article detail page, we can call the comment list like this:

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

here,commentsIs a custom variable name used to store the obtained comment data.archiveId=archive.IdThe parameter is crucial, it tells the system that we want to retrieve the articles on the current page (archive.Idrepresenting the ID of the current article).type="list"which means to retrieve comments in list form,limit="6"It limited the number of displayed comments.

BycommentListTags retrieved from comments.commentsA variable is an array where eachitemAll represent a single comment. TheseitemIt includes various details of the comments, such as:

  • Id: The unique identifier of the comment.
  • UserName: The username of the commentor.
  • Content: The actual content of the comment.
  • CreatedTime: The comment publication time, usually needs to be formatted with tags (stampToDate) to become a readable date.
  • Status: The comment review status, for exampleStatus = 1indicating the review has passed,Status = 0means under review.
  • VoteCount: The number of likes received from comments.

We can useforLoop throughcommentsArray, display each comment in the form we want.

Implementing comment reply levels: Deep interactive display.

AnQiCMS's comment feature supports multi-level replies, which means users can not only comment on the article itself but also reply to other users' comments, forming a conversation hierarchy. To correctly display this reply relationship on the front end, we need to use commentsitemofParentIdandParentfield.

ParentIdRecorded the ID of the parent comment that the current comment replies to.ParentField is more convenient, it directly contains the complete parent comment object.itemWe can check through.item.ParentWhether it exists to judge whether the current comment is a reply.

The following code snippet shows how to judge and display reply comments:

{% commentList comments with archiveId=archive.Id type="list" limit="6" %}
    {% for item in comments %}
    <div class="comment-item">
        <div class="comment-header">
            <span>{{item.UserName}}</span>
            <span>于 {{stampToDate(item.CreatedTime, "2006-01-02 15:04")}} 发布</span>
        </div>
        {% if item.Parent %}
        <div class="comment-reply-to">
            <blockquote class="blockquote-sm">
                回复 <span class="reply-user">{{item.Parent.UserName}}</span>:
                <p>{{item.Parent.Content|truncatechars:100}}</p> {# 截取父评论内容,避免过长 #}
            </blockquote>
        </div>
        {% endif %}
        <div class="comment-content">
            {% if item.Status != 1 %}
            <p class="text-muted">评论正在审核中...</p>
            {% else %}
            <p>{{item.Content}}</p>
            {% endif %}
        </div>
        <div class="comment-actions">
            <a class="praise-btn">赞 ({{item.VoteCount}})</a>
            <a class="reply-btn" data-parent-id="{{item.Id}}" data-reply-user="{{item.UserName}}">回复</a>
        </div>
    </div>
    {% endfor %}
{% endcommentList %}

In this example:

  • We first displayed the username and posting time of the current reviewer.
  • {% if item.Parent %}Determine whether the current comment is a reply.
  • Ifitem.ParentIf it exists, we will render it.blockquoteStyle to highlight which user it replied to, as well as part of the parent comment (item.Parent.UserName,item.Parent.Content) here it usedtruncatechars:100Filter to prevent the parent comment content from being too long and affecting the layout.
  • Next, display the content of the current comment and judgeitem.Statuswhether it is under review.
  • Finally, interactive buttons for liking and replying were provided.

In this way, comments are not only presented as a flat list, but also as a back-and-forth conversation, greatly enhancing the user experience.

Practical display skills for comment lists

In addition to displaying basic comments and replies, AnQiCMS also provides other practical features to improve the user experience of the comment system:

  1. Comment list with pagination:If the number of comments is large, loading all of them at once will affect the page performance. At this time, you cancommentListlabel'stypethe parameter to"page"and combiningpaginationuse tags to implement pagination of comments, enhancing the user's browsing experience.

    {% commentList comments with archiveId=archive.Id type="page" limit="10" %}
        {# 评论内容 #}
    {% endcommentList %}
    
    {% pagination pages with show="5" %}
        {# 分页导航条 #}
    {% endpagination %}
    
  2. Comment review and user-friendly prompts: item.StatusThe field allows us to flexibly control the display of comments. ForStatusnot equal to1Comments that have not passed the review can display the prompt 'Comments are being reviewed...' This informs the user that the comment has been submitted while maintaining the quality of the website content.

  3. Like function integrated: item.VoteCountLikes can be displayed directly. Combined with front-end JavaScript and the comment like API provided by AnQiCMS (/comment/praiseWe can implement a dynamic like function to increase the interactivity of comments.

  4. Comment form and anti-spam comments:Comments are usually submitted through a form, AnQiCMS provides./comment/publishThe interface receives comment data. To prevent spam comments, the system also supports integrated captcha functionality. Add a captcha field to the comment form and cooperate withcaptchaThe template tags provided interface can effectively improve the security of comments.

The comment feature of AnQiCMS, through flexible template tags and detailed data structures, provides website operators with powerful customization capabilities.Whether it is a simple comment display or a complex reply level interaction, it can be easily realized at the template level, thus building an active and user-friendly content community.

Frequently Asked Questions (FAQ)

1. How to prevent spam or malicious comments from appearing in the comment section?AnQiCMS provides a backend comment review feature, you can set comments to be manually reviewed before they are displayed.At the same time, the system also supports integrated graphic captcha, you can enable the captcha in the comment form to effectively intercept spam comments submitted by robots and automated submissions.

2. Can the display level of the comment list be nested infinitely?In most cases, to maintain the clarity of the comment area and the user experience, AnQiCMS will have a reasonable depth limit when displaying reply levels.Although it is technically possible to implement multi-level nesting, it is recommended not to design too deep a reply level on the front end to avoid the page being too complex and long.You can control the visual nesting depth of the reply by customizing CSS and JavaScript.

3. How should I obtain the total number of comments to display next to the comment list?You can use it on the article detail page.archiveDetailTag to get the total number of comments on the current article. For example:{% archiveDetail with name="CommentCount" %}You can directly output the number of comments on the current article.

Related articles

How to add and display friendship links on the Anqi CMS website?

In website operation, friendship links play an indispensable role.They not only help to improve the search engine ranking (SEO) of a website, but also bring potential traffic and improve the user experience, allowing visitors to get more information through related websites.AnQiCMS (AnQiCMS) understands this and therefore provides an intuitive and convenient friend link management feature, allowing you to easily add, manage, and display these important external connections.This article will introduce in detail how to add friend links in the Anqi CMS background, as well as how to flexibly display them on the website's front-end template

2025-11-08

How to display and manage the website message form of AnQi CMS and customize fields?

The website message form is an important link between users and the website, it not only helps us collect valuable opinions and suggestions, but also lays the foundation for various interactive functions such as user consultation and service reservation.AnQi CMS is well-versed in this, providing website operators with a straightforward, efficient, and highly customizable feedback form solution, making it exceptionally simple to manage and customize form fields.### Easily build the frontend presentation of the message form In Anqi CMS, to display the message form on the website page, you do not need to write complex backend logic, just insert the specific tags in the template file

2025-11-08

How to retrieve and display the document list under a specified Tag in AnQi CMS?

AnQiCMS (AnQiCMS) offers great convenience to website operators with its flexible content management and powerful template engine.In daily content operation, we often need to aggregate and display lists of related documents based on specific tags (Tag), such as 'Hot Topics', 'Technical Tips', or 'Product Reviews' and so on.This not only helps users quickly find the content they are interested in, but also effectively improves the internal link structure of the website, which is very beneficial for SEO.This article will delve into how to retrieve and display a list of documents under a specified tag in AnQiCMS

2025-11-08

How to set and display a custom template on a single page of AnQi CMS?

AnQi CMS, with its powerful flexibility and ease of use, has become a helpful assistant for many content operators.Especially in terms of content display, it provides us with rich customization space.For those web pages that require unique layouts or specific functions, such as "About Us", "Contact Us", or a special event landing page, we often hope that they can have a completely different visual style from ordinary articles or list pages.Aqii CMS provides a very convenient way for us to set exclusive custom templates for these single-page websites

2025-11-08

How can conditional judgments (if/else) be used in the AnQi CMS template to control content display?

AnQiCMS template development skills: flexibly use conditional judgment (if/else) to control content display In website content operation, we often need to display or hide specific content blocks based on different conditions, or to differentiate the display based on different data states. AnQiCMS (AnQiCMS) powerful template engine provides us with flexible conditional judgment capabilities, through the clever use of `if/else` statements, you can easily achieve the fine-grained control of content, making your website more dynamic and user-friendly.

2025-11-08

How to perform a loop (for) in Anqi CMS template to display list data?

When building a website page, we often need to display various list data, such as the latest articles, product categories, navigation menus, or comment details.The template system of AnQiCMS provides us with a powerful and flexible loop traversal function, making the display of dynamic lists very simple.The template syntax of AnQi CMS borrows from the Django template engine, so users familiar with this syntax will feel very close.It uses the `for` loop label to iterate over the data collection and display each item one by one.###

2025-11-08

How to format a timestamp into a readable date and time format and display it in AnQi CMS?

In website content operations, the presentation of time is often ignored, but it is an important detail for improving user experience and content professionalism.The original timestamp number lacks meaning for ordinary users. Formatting it into a clear and easy-to-read date and time format makes the content more appealing.AnQi CMS knows this, providing a simple and powerful way to handle such needs.### Understanding the timestamp in AnQi CMS In AnQi CMS, whether it is the publication time (`CreatedTime`) or the update time (`UpdatedTime`)

2025-11-08

Does AnQi CMS support the automatic conversion of uploaded images to WebP format for optimized display?

In the era where content is king, the loading speed of website images directly affects user experience and search engine optimization (SEO) performance.Efficient image management and optimization strategies are crucial for any website committed to providing high-quality content services.Many website operators are actively seeking solutions that can automatically optimize images, especially those converted to WebP format.So, for those who are using or considering using AnQiCMS, does this system support automatic conversion of images to WebP format after upload to optimize display?The answer is affirmative

2025-11-08