How to display the AnQiCMS comment list on the front end and show the reply level and like count?

Calendar 👁️ 74

In website content operation, user comments are an important part of building community atmosphere, enhancing content interaction, and collecting user feedback.AnQiCMS (AnQiCMS) fully understands this, providing a powerful and flexible comment management feature, and through its powerful template engine, allowing you to easily display comments on the front-end page, including reply levels and likes count and other detailed information.

Next, we will together learn how to use the template tags and fields of Anqi CMS to clearly present these comments on your website.

AnQiCMS Comment Function Overview

The comment feature of AnQi CMS is designed to be simple and efficient, just like the other parts of its content management system.It allows users to post comments below articles, products, and other content, and to manage them centrally through the backend.Especially in the front-end display, AnQi CMS empowers users with high customization capabilities through predefined template tags, allowing you to flexibly control the display of comments according to the design style and user experience needs of the website.

Core: utilizingcommentListTag Display Comments

To display comments on the front-end page, we mainly use AnQiCMS'scommentListTemplate tag. This tag is specifically used to retrieve the comment list for specified content.

Generally, comments will be attached to an article or product. Therefore, when usingcommentListWhen labeling, we need to clearly inform the system which article or product comments you want to retrieve. This can be done byarchiveIdParameters are used to implement. In an article or product detail page, the ID of the current content is usually obtained througharchive.IdGet it.

The following is a basic example of a comment list call:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 评论循环体,稍后详细解释 #}
{% endcommentList %}

Here:

  • commentsIs the variable name you set for the comment list, you can access the data of each comment in subsequent operations.forthrough the loopitem(Or you can use a custom loop variable name) to access the data of each comment.
  • archiveId=archive.IdIndicated that we are retrieving the comments corresponding to the current detail page article (or product).
  • type="page"We hope that this comment list supports pagination, so that when the number of comments is large, they can be displayed on different pages.
  • limit="10"Then set 10 comments to be displayed per page.

Clear display of reply levels

Interactions between users often take the form of replies, displaying the reply relationship of comments can make the discussion more organized. Anqi CMS'scommentListA tag contains oneParentA field that stores the detailed information of the parent comment to which the current comment is replying. Using this field, we can build a hierarchical reply display on the front end.

Whenitem.ParentWhen present, it means that the current comment is a reply to another comment. We can adjust the display style by judgingitem.Parentwhether it exists, such as using a block quote (<blockquote>To highlight the content being replied to and indicate which user's comment was replied to.

Here is an example code snippet showing the reply hierarchy.

{% commentList comments with archiveId=archive.Id type="list" limit="6" %}
    {% for item in comments %}
    <div class="comment-item">
      <div class="comment-header">
        <span class="username">
          {% if item.Status != 1 %}
          审核中:{{item.UserName|truncatechars:6}}
          {% else %}
          {{item.UserName}}
          {% endif %}
        </span>
        {% if item.Parent %} {# 如果存在父级评论,说明是回复 #}
        <span class="reply-to">回复</span>
        <span class="parent-username">
          {% if item.Parent.Status != 1 %}
          审核中:{{item.Parent.UserName|truncatechars:6}}
          {% else %}
          {{item.Parent.UserName}}
          {% endif %}
        </span>
        {% endif %}
        <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
      </div>
      <div class="comment-content">
        {% if item.Parent %} {# 显示父级评论的引用内容 #}
        <blockquote class="parent-comment-quote">
          {% if item.Parent.Status != 1 %}
          该内容正在审核中:{{item.Parent.Content|truncatechars:9}}
          {% else %}
          {{item.Parent.Content|truncatechars:100}}
          {% endif %}
        </blockquote>
        {% endif %}
        {% if item.Status != 1 %} {# 当前评论内容 #}
          该内容正在审核中:{{item.Content|truncatechars:9}}
        {% else %}
        {{item.Content}}
        {% endif %}
      </div>
      {# 点赞和回复操作区,稍后解释 #}
      <div class="comment-actions">
        <a class="praise-button" data-id="{{item.Id}}">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a>
        <a class="reply-button" data-id="{{item.Id}}" data-user="{{item.UserName}}">回复</a>
      </div>
    </div>
    {% endfor %}
{% endcommentList %}

In this example, we use{% if item.Parent %}To determine whether the current comment is a reply. If it is, display the word "reply" and quote the username and part of the content of the parent comment so that the user can see at a glance. At the same time, we also useditem.StatusTo determine whether the comment is under review, so that the corresponding prompt can be given.

Display the number of likes directly.

Liking is an important indicator of the popularity of comments. Anqi CMS provides this for each comment data.VoteCountThe field directly stores the number of likes the comment has received. You just need to refer to this field in the template to display it on the frontend.

In the above code example, you can see the way the like count is displayed:

<a class="praise-button" data-id="{{item.Id}}">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a>

Here{{item.VoteCount}}The number of likes for the current comment will be displayed directly. Usually, to achieve the effect of real-time update of the number of likes after the user clicks the like button, we will combine JavaScript and the backend API (such as the one provided by Anqi CMS)/comment/praiseAn interface is used to achieve dynamic interaction, but that is the scope of front-end JS, and here we mainly focus on data display.

Comments submission and interaction (briefly mentioned)

In order for users to be able to post comments or like, you also need to place a comment submission form below or next to the comment list and bind a JavaScript event to the like button.

Comment submission form:A basic comment submission form needsarchive_id(Current article ID),user_name/contentetc. To reply to a specific comment, you need to addparent_id. The submission address is/comment/publish.

<form method="post" action="/comment/publish">
  <input type="hidden" name="archive_id" value="{% archiveDetail with name="Id" %}">
  <input type="hidden" name="parent_id" value="" id="parent-comment-id"> {# 用于回复 #}
  <input type="text" name="user_name" placeholder="您的昵称" required>
  <textarea name="content" placeholder="您的评论" required></textarea>
  <button type="submit">发表评论</button>
</form>

Comment like interaction:The like function can be monitored by the front-end JavaScript for the click event of the like button, and then send a POST request through AJAX to/comment/praisethe interface with the commentid. After successful update on the pageVoteCountdisplay.

Comment list pagination processing

When there are many comments, reasonable pagination can improve page loading speed and user experience. IncommentListSet in the labeltype="page"After that, you can combinepaginationtags to generate pagination navigation.

`twig {# Comment list code (as shown in the example) #}

{# Pagination code #}

{% pagination pages with show="5" %}
<ul>
    {# 首页、上一页、中间页、下一页、尾页的显示逻辑 #}
    <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
    {% if pages.PrevPage %}
        <li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
    {% endif %}
    {% for item in pages.Pages %}
        <li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
    {% endfor %}
    {% if pages.NextPage %}
        <li><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name

Related articles

How to use a for loop in AnQiCMS template and control the special display style of the first or last item in the loop?

When building a website, we often need to finely control the elements in the list, especially when displaying list data, setting a unique style for the first or last item in the list is a common requirement.For example, you may want the first product image in the list to be larger, or to not display the separator at the end of the news list.AnQiCMS's powerful template system provides an intuitive and flexible way to meet such needs.AnQiCMS's template system is based on Go language, but its syntax style is very similar to the Django template engine

2025-11-09

Does AnQiCMS support automatically converting uploaded JPG/PNG images to WebP format to improve page loading speed?

The importance of page loading speed in website operation is self-evident.A fast-loading website not only improves user experience and reduces bounce rate, but is also one of the key factors in search engine optimization (SEO).Images are an important part of web content, and their loading efficiency directly affects the overall performance of the page.Therefore, converting traditional JPG/PNG images to the smaller and more efficient WebP format has become the mainstream trend of website optimization.When using the AnQiCMS website management, if you have ever been confused about how to automatically optimize the uploaded images

2025-11-09

How to implement batch management and classification of image resources in AnQiCMS for easy front-end calls?

In today's era where content is king, images, as an important carrier of information, directly affect the user experience and operation efficiency of the website through their management and call efficiency.For AnQiCMS users, batch management and flexible invocation of image resources are not difficult things.This system not only provides intuitive and convenient background operations, but also enhances the brilliance of image resources when presented on the front end through intelligent image processing and rich template tags.### Build a comprehensive image library: from batch upload to precise classification The richness of website content depends on a large amount of image materials, and how to organize these materials efficiently

2025-11-09

How does AnQiCMS handle external links in content, is it retained directly or automatically added nofollow attribute?

In website operation, the management of external links is a detail that cannot be ignored. It not only relates to user experience but is also an important part of SEO strategy.We often ponder: When publishing content, how will AnQiCMS handle links to other websites included in the article?Is it simply to keep it as it is, or will it intelligently add the `nofollow` attribute, even directly remove these links?AnQiCMS provides a clear and powerful control strategy for handling external links in content

2025-11-09

How to safely output the article content containing HTML tags in a template, preventing XSS attacks while maintaining the format?

In website content operation, we often need to publish articles containing images, links, paragraph styles, and other rich formats.AnQiCMS (AnQiCMS) is a powerful content management system with a flexible template engine that can help us easily display these contents.However, while enjoying the convenience, we must also pay attention to a core issue: how to safely output the article content with HTML tags in the template, while maintaining its original beautiful format and effectively preventing potential cross-site scripting (XSS) attacks

2025-11-09

Does AnQiCMS provide a feature for dynamically displaying the current year tag?

In the daily operation of website content, we often encounter some elements that need to be dynamically updated, the most common of which is the year in the copyright statement.If you need to manually change the year at the bottom of the website every year, it not only takes time and effort, but is also prone to omissions.As a pursuit of efficient and intelligent content management system, can AnQiCMS provide us with a solution to automatically update the current year?The answer is affirmative. AnQiCMS fully considers these subtle needs in website operation and has built-in corresponding tag functions for its template engine.

2025-11-09

How to set up scheduled article publishing in AnQiCMS to achieve automated content display?

In today's internet age where content is king, the continuous update and efficient operation of website content is the key to attracting and retaining users.However, manual timed release is not only time-consuming and labor-intensive, but may also miss the**release opportunity due to negligence.AnQiCMS addresses this pain point by building a convenient scheduled publishing function, which helps us easily achieve automated content display.Why choose scheduled publication to achieve content automation?Timely publishing is not only a tool to improve efficiency, but also an indispensable part of content operation strategy.The benefits it brings are obvious: *

2025-11-09

How to display custom contact information on the website frontend, such as WhatsApp or Facebook links?

In today's digital age, allowing customers to easily find and contact you is the cornerstone of any successful website.Whether it is to provide customer support, promote sales, or build community interaction, clear and visible contact information is crucial. 幸运的是,AnQi CMS provides a set of intuitive and powerful features that allow you to easily display various custom contact methods on your website front-end, such as WhatsApp or Facebook links, ensuring that your customers can always communicate with you conveniently.Next, we will step by step introduce how to achieve this goal in Anqi CMS

2025-11-09