How to display the list of user comments on articles in AnQi CMS?

Calendar 👁️ 67

In Anqi CMS, allowing users to comment on articles and clearly displaying these comments is an important link to enhance the interactivity and user engagement of the website.AnQiCMS has a powerful template engine and built-in features that make this process flexible and efficient.This article will provide a detailed introduction on how to integrate the comment list and its related features on the article detail page.


1. Understand the comment mechanism and template structure of Anqi CMS

The AnQi CMS is built with a comprehensive comment management feature, supporting users to submit comments on article pages and manage them uniformly in the background.These comments need to be displayed on the front-end page, mainly involving the editing of the website template.

In AnQiCMS, the article detail page usually corresponds to the template directory under{模型table}/detail.html(or the flat mode under{模型table}_detail.html)file. All modules related to article content display, as well as comments related to the article, and previous/next articles, will be called and laid out in this template file.

Core ideaIt utilizes the template tags provided by AnQiCMS to dynamically retrieve the comment data of a specified article from the database and render it on the page.

Second, display comments list on the article detail page

To display comments on the article detail page, you need to use the provided by AnQiCMScommentListThe tag is specifically used to retrieve the comment list or comment pagination list of a document.

Firstly, make sure you are editing the template file of the article detail page (for example,template/default/article/detail.html)

1. Get the current article ID

commentListThe tag needs to know which article's comment it is. On the article detail page, the current article's ID can be accessed directly througharchive.IdbecausearchiveVariables usually represent the detailed data of the current article.

2. UsecommentListTag to get comment data

We can call it like thiscommentListTag to get comment data:

{% commentList comments with archiveId=archive.Id type="list" limit="10" order="id desc" %}
    {# 这里的 `comments` 是一个数组,包含了当前文章的评论数据 #}
    {% for item in comments %}
    <div class="comment-item">
        <div class="comment-header">
            <span class="username">
                {% if item.Status != 1 %}
                {# 评论状态为0表示审核中,可以做匿名处理或提示 #}
                审核中:{{item.UserName|truncatechars:6}}
                {% else %}
                {{item.UserName}}
                {% endif %}
            </span>
            {% if item.Parent %}
            {# 如果是回复某条评论,会存在Parent对象 #}
            <span class="reply-to">回复 {{item.Parent.UserName}}</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="reply-quote">
                {% if item.Parent.Status != 1 %}
                原评论审核中:{{item.Parent.Content|truncatechars:100}}
                {% else %}
                {{item.Parent.Content|truncatechars:100}}
                {% endif %}
            </blockquote>
            {% endif %}

            {% if item.Status != 1 %}
            该内容正在审核中,稍后可见。
            {% else %}
            {{item.Content|safe}} {# 注意这里使用 |safe 过滤器,以防评论内容包含HTML #}
            {% endif %}
        </div>
        <div class="comment-actions">
            <a class="praise-btn" data-id="{{item.Id}}">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a>
            <a class="reply-btn" data-id="{{item.Id}}" data-user="{{item.UserName}}">回复</a>
        </div>
    </div>
    {% endfor %}
{% empty %}
    <p>暂无评论,快来发表您的看法吧!</p>
{% endcommentList %}

Code explanation:

  • comments: The variable name we define for the comment list.
  • archiveId=archive.Id: Specify the retrieval of the current article (ID isarchive.Id) comments.
  • type="list": Indicates that a fixed number of items is to be retrieved instead of a paged list. If you wish to have the comment list paged, please settypeis set to"page".
  • limit="10": Display 10 comments per page (or each display).
  • order="id desc": Sort comments by ID in descending order, so the latest comments are displayed at the top.
  • {% for item in comments %}: Traverse the obtained comment data.
  • item.Status: Review status of the comment.1Means approved, other values may indicate in review or not approved. Usually, only approved comments are displayed for user experience, or a hint is given for comments in review.
  • item.ParentIf this comment is a reply to another comment,item.Parentit will include the details of the replied comment, which helps to build the style of nested comments.
  • {{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}: Use.stampToDateThe filter converts timestamps into a readable date and time format.
  • {{item.Content|safe}}: Display the comment content.Important reminder:User submitted comment content may contain HTML tags.To prevent XSS attacks, AnQiCMS defaults to escaping the output.If your comment editor allows users to submit rich text (with HTML tags) and you want these HTML tags to be parsed by the browser, then

Related articles

How does Anqi CMS display and manage website friend links?

In website operation, friendship links play an important role. They not only help to improve the website's search engine ranking (SEO), but also bring valuable traffic, and are also a manifestation of cooperation and mutual trust between websites.Anqi CMS is well-versed in this, providing website operators with a直观 and efficient buddy link management and display solution, allowing you to easily master this feature.Next, we will delve into how to manage friend links in the background, to how to flexibly display them on the website frontend, and provide you with a detailed explanation of the friend links feature of Anqi CMS.

2025-11-08

How to display a list of recommended content related to the current article?

In content operation, guiding users to discover more interesting content is one of the key strategies to enhance user experience and extend the time spent on the website.AnQiCMS (AnQiCMS) provides very flexible and powerful features, helping us easily achieve the goal of displaying a list of recommended content related to the current article.Why is it necessary to have relevant recommended content?

2025-11-08

How to display the link to the previous and next article on the Anqi CMS content page?

In AnQi CMS, it is a common need to add navigation links for "Previous Article" and "Next Article" to enhance the user experience of the website and the efficiency of internal links.These links not only help visitors browse related content more smoothly, but also have a positive impact on the website's SEO performance.AnQi CMS provides a set of intuitive template tags that allow you to easily display these navigation features on the content detail page.### Core Function: Use `prevArchive` and `nextArchive` tags Anqi CMS passes through

2025-11-08

What tags does Anqi CMS provide to display content publishing or update time information?

In website content operation, the time of content release and update is a key factor in conveying information timeliness and establishing user trust.For search engine optimization (SEO), clear time information also helps improve the freshness score of the content.Anqi CMS is well-versed in this, providing users with flexible and diverse tags and methods to accurately and beautifully display these time information on the website front-end.Next, we will explore how Anqi CMS helps us manage and display the content publication and update time.###

2025-11-08

How to build and display a custom field comment form on the front-end page?

When you want website visitors to be able to interact with you, such as submitting questions, providing feedback, or making appointments, a well-functioning contact form is essential.AnQiCMS provides a very flexible and powerful message management function, the core of which is to support custom message fields, allowing you to build personalized forms according to your actual business needs.This article will guide you on how to build and display these comment forms with custom fields on the front-end page.Why do you need a custom message form?

2025-11-08

How to display system-level configurations such as the website logo, filing number, copyright information, etc.

The brand identity, legal statements, and core contact information, such as Logo, filing number, and copyright information, are an indispensable part of the professional image of a website.They not only convey trust and standardization to visitors, but are also important aspects of search engine optimization and legal compliance.In Anqi CMS, managing and displaying these system-level configurations becomes extremely intuitive and efficient. ### Backend Settings: The "Control Center" of Website Information AnQi CMS concentrates these core website information in the "Global Settings" of the backend, making management clear at a glance.

2025-11-08

How to embed and display mathematical formulas or flowcharts from the Markdown editor in the content?

In modern content operation, the professionalism and readability of the content are equally important.Especially when our website involves fields such as science, education, engineering, and so on, how to clearly and beautifully present complex mathematical formulas or logically rigorous flowcharts in articles often becomes the key to improving user experience.AnQi CMS understands this need, integrating a powerful Markdown editor and combining it with simple frontend configuration, allowing your website to easily present these professional contents.### First Step

2025-11-08

How does Anqi CMS handle images in content to optimize loading speed and display quality (WebP, compression)?

In the content of the website, images play a crucial role, they can enrich the visual effects and convey complex information.However, unoptimized images are often the culprit for slow website loading and poor user experience.As content operators, we fully understand the value of image optimization in improving website performance and user retention.AnQiCMS provides a series of powerful and intelligent functions in image processing, aiming to help us easily achieve a balance between image loading speed and display quality.

2025-11-08