How to display the user comment list on the article detail page and support

Calendar 👁️ 68

In website operation, the user comment feature on the article detail page is a key to enhancing user interaction and website activity.AnQiCMS (AnQiCMS) provides powerful and flexible comment management capabilities, allowing you to easily display comment lists on article detail pages and support user comment submissions, even further enhancing comment functions.

1. Preparation: Understand the comment mechanism and template structure

In AnQi CMS, each article can independently enable the comment function.When a user submits a comment on the article detail page, these comments will be associated with the corresponding article.To implement the display and submission of comments, we mainly do it in the article detail page template (usually archive/detail.htmlOr perform operations in a custom article detail template) . Anqi CMS uses GoLang template engine syntax, similar to Django templates, to call data and implement logic through specific tags.

The core idea is:

  • Display comment list: Use the built-in comment list tagcommentListTo get related comments, pass the ID of the current article.
  • Submit comment form:Create an HTML form and submit it to the comment release interface provided by AnQi CMS.
  • Enhance functionality:According to requirements, you can integrate captcha, like comments, and more.

2. Display the comment list on the article detail page

To display user comments on the article detail page, you need to usecommentListLabel. This label can help you get the comment data associated with the current article and supports pagination display.

First, make sure that your article detail template has correctly obtained the information of the current article. In the article detail template, you can usually directlyarchive.Idretrieve the ID of the current article.

Next, insert the following code at the position where you want to display the comment list:

{# 确保您已经获取了当前文章的ID,例如这里假设当前文章对象为 archive #}
<div class="comments-section">
    <h3>用户评论 ({{ archive.CommentCount }}条)</h3>
    {% commentList comments with archiveId=archive.Id type="page" limit="10" order="id desc" %}
        {% for item in comments %}
        <div class="comment-item">
            <div class="comment-meta">
                <span class="comment-author">
                    {% if item.Status != 1 %}
                        <!-- 如果评论处于审核中,可以显示不同的提示或用户名 -->
                        审核中用户: {{ item.UserName|truncatechars:6 }}
                    {% else %}
                        {{ item.UserName }}
                    {% endif %}
                </span>
                {% if item.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 %}
                    该评论内容正在审核中...
                    {% else %}
                    {{ item.Parent.Content|truncatechars:100 }}
                    {% endif %}
                </blockquote>
                {% endif %}
                {% if item.Status != 1 %}
                <p>该评论内容正在审核中,请耐心等待。</p>
                {% else %}
                <p>{{ item.Content }}</p>
                {% endif %}
            </div>
            <div class="comment-actions">
                <a class="item vote-comment" data-id="{{ item.Id }}">
                    赞 (<span class="vote-count">{{ item.VoteCount }}</span>)
                </a>
                <a class="item reply-comment" data-id="{{ item.Id }}" data-user="{{ item.UserName }}">回复</a>
            </div>
        </div>
        {% empty %}
        <p class="no-comments">还没有评论,快来发表您的看法吧!</p>
        {% endfor %}
    {% endcommentList %}

    {# 评论分页显示 #}
    {% pagination pages with show="5" %}
    <div class="comment-pagination">
        {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}" class="prev-page">上一页</a>{% endif %}
        {% for page_item in pages.Pages %}
            <a href="{{ page_item.Link }}" class="page-number {% if page_item.IsCurrent %}current{% endif %}">{{ page_item.Name }}</a>
        {% endfor %}
        {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}" class="next-page">下一页</a>{% endif %}
    </div>
    {% endpagination %}
</div>

In this code:

  • archiveId=archive.Id: Make sure that the comment list only displays the comments of the current article.
  • type="page": Enable pagination,limit="10"It means 10 comments are displayed per page.
  • order="id desc": Sorted in descending order by ID, the latest comments are displayed at the top.
  • item.Status != 1: Comment status judgment,1Means the review has been approved. You can manage and review comments in the background.
  • item.Parent: is used to handle comment replies if anyitem.Parentmeans it is a reply to another comment.
  • stampToDateThe colon is a label provided by AnqCMS for formatting timestamp.
  • paginationThe label is responsible for generating pagination links for the comment list.

3. Implement the comment submission form.

A form is needed for users to submit comments and send the data to the Anqi CMS comment publishing interface/comment/publish. To support the reply function, an optionalparent_idfield.

This is an example of a basic comment submission form:

`twig <div class="comment-form"

Related articles

Can I set multiple Banner groups in AnQiCMS and display them at different positions separately?

In AnQiCMS, you can completely set up multiple Banner groups and flexibly display them in different positions according to the website layout.AnQiCMS provides a multi-dimensional way to manage and call these important visual elements to help you better organize website content and attract visitors.### One, the core concept of Banner management in AnQiCMS AnQiCMS demonstrates high flexibility and customization in Banner management

2025-11-08

How to set and call the thumbnail of an article, category, or single page, and control its display size?

In website operation, images are not only an important part of content attractiveness, but also a key factor affecting page loading speed and user experience.Especially for articles, categories, or single-page content, an appropriate thumbnail can quickly catch the visitor's attention and guide them to click for more in-depth information.In Anqi CMS, setting and calling these thumbnails, and flexibly controlling their display size, is actually simpler and more efficient than imagined.### Easily manage thumbnails on the backend: Upload and intelligent extraction First, let's learn how to set thumbnails for your content on the Anqi CMS backend

2025-11-08

How to enable lazy loading of images in article content to speed up page loading and improve user experience?

In website operation, page loading speed and user experience are always the core concerns.Images are often a major component of web content and also one of the main factors affecting page loading speed.A high-definition image can enhance the visual effects, but too many images without proper handling will slow down the website speed and make visitors hesitate.Fortunately, AnQi CMS has provided us with a very convenient image lazy loading (Lazy Load) feature, which helps us effectively solve this problem.In simple terms, lazy loading of images is about not loading all images at once when the page loads

2025-11-08

How to configure AnQiCMS to automatically convert uploaded images to WebP format for optimized display performance?

The loading speed of a website is one of the key factors in user experience and search engine optimization, and images, as an important part of web content, often occupy most of the time it takes to load a page.Convert images to more efficient formats like WebP, which can significantly reduce the size of image files, thereby improving the display performance of websites.AnQiCMS as a content management system that focuses on performance and user experience, is built with the feature of automatically converting images to WebP format.This article will give a detailed introduction on how to configure this feature in AnQiCMS, making your website images automatically optimized during upload

2025-11-08

How to customize the display layout of the article detail page in AnQiCMS?

In AnQi CMS, the layout customization of the article detail page is a key factor in improving the user experience and display effect of the website.Benefiting from its flexible template mechanism, we can easily create unique article detail pages according to specific needs.Below, we will delve into the process of locating template files, core data calls, and how to use advanced features to achieve personalized layouts, among other aspects.### Understand the template working mechanism of AnQi CMS The template system of AnQi CMS is the foundation of its flexibility, it uses syntax similar to Django template engine

2025-11-08

How to make AnQiCMS website content adaptable to mobile display?

AnQiCMS is committed to providing users with an efficient and flexible content management experience, of course, also fully considering the display needs of the website on different devices, especially the increasingly important mobile display.Let your AnQiCMS website content adapt to mobile devices easily, it's not a difficult thing.AnQiCMS provides various flexible strategies to ensure your website offers an excellent user experience on any device.### The Flexible Adaptation of AnQiCMS AnQiCMS deeply understands the diverse display needs of mobile devices

2025-11-08

Under multi-site management, how can you ensure that each site displays its content independently?

How to ensure that the content of each site can be displayed independently when managing multiple websites is a common challenge faced by many content operators.Fortunately, AnQiCMS (AnQiCMS) took this into consideration from the very beginning, through a clever mechanism, allowing content to be managed uniformly across multiple site environments while also remaining independent and not interfering with each other. ### The core mechanism of AnQi CMS for independent content display The reason why AnQi CMS can easily handle the independent display of content across multiple sites lies in the physical and logical dual isolation provided for each site.View from a physical perspective

2025-11-08

How does AnQi CMS support displaying personalized content model data?

Unlock the personalized display potential of content model data in today's content marketing and website operations, how to efficiently and flexibly display content is the key to success.We all know that the content format of each website is not the same, some need to display articles, some need to display products, and some may need to publish event information, recruitment lists, and so on.If the system cannot support these diverse content structures, it will be very limited in operation.Aqí CMS was born to solve this pain point.It provides a **flexible content model** feature, allowing us to meet actual business needs

2025-11-08