How to display a list of user-submitted comments on a website and handle the review status?

Calendar 👁️ 67

In website operation, user comments are an important element for building a community, obtaining feedback, and enhancing content interaction.For friends using AnQiCMS (AnQiCMS) to build and manage websites, efficiently displaying user comments and managing their review status is a key factor in ensuring the quality of website content and user experience.The AnQiCMS provides very flexible and practical features for this.

How to display a user comment list on a page

To display user-submitted comments on your website, you will use the powerful template tag system of AnQiCMS, especiallycommentListThe tag can help us easily retrieve comment data from the database and present it on the front page in the way we want.

Comments are usually associated with specific articles or products, and therefore, when usingcommentListWhen labeling, we need to specify the content ID of the comment. For example, if you want to display comments below the details page of an article, you can usearchiveIdParameters are used to pass the current article ID. This article ID can be obtained througharchiveDetailtags easily, such asarchive.Id.

You can also pass throughtypeParameters to control the display of the comment list. When you only need to retrieve a certain number of the latest comments (such as for the sidebar display), you cantypeis set to"list"And thenlimitParameter limits the number of displays. If it is in the comment area, it requires a complete comment list and pagination feature, thentypeis set to"page".

Here is a basic comment list code example, which retrieves the latest 5 comments of the current article:

{# 假设我们正在一个文章详情页,archive.Id代表当前文章的ID #}
{% commentList comments with archiveId=archive.Id type="list" limit="5" %}
    {% for item in comments %}
        <div>
            <strong>{{ item.UserName }}</strong> 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}
            <p>{{ item.Content }}</p>
        </div>
    {% empty %}
        <p>目前还没有评论。</p>
    {% endfor %}
{% endcommentList %}

In this code block,item.UserNameDisplay the nickname of the commentor,item.Contentwhich is the specific content of the comment,item.CreatedTimeIt is the timestamp of the comment submission. To make the time display more friendly, we usedstampToDatea filter to format it into a common date and time format.{% empty %}Tags are displayed as a prompt when there are no comments.

Review status of comments processing

After the user submits a comment, there is usually a review process. AnQiCMS has built-in comment review mechanisms, each comment has aStatusfield to indicate its review status. Usually,Status = 1Indicates that the comment has been approved and can be publicly displayed, whileStatus = 0means that the comment is being reviewed or has not been approved.

When displaying the comment list on the front end, we should judge according toStatusThe field determines how to display.For comments under review, we can choose not to display the full content or show a "Under review" prompt to ensure the compliance of the website content.

Integrate the review status logic into the comment list, for example:

`twig {% commentList comments with archiveId=archive.Id type="list" limit="5" %}

{% for item in comments %}
    <div class="comment-item">
        <div class="comment-meta">
            <strong>
                {% if item.Status == 1 %}
                    {{ item.UserName }}
                {% else %}
                    {# 评论审核中,只显示部分用户名或匿名处理 #}
                    审核中:{{ item.UserName|truncatechars:6 }}
                {% endif %}
            </strong> 发表于 {{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}
        </div>

        {# 处理回复评论的显示 #}
        {% if item.Parent %}
            <blockquote class="reply-blockquote">
                {% if item.Parent.Status == 1 %}
                    回复 <strong>{{ item.Parent.UserName }}</strong>: {{ item.Parent.Content|truncatechars:100 }}
                {% else %}
                    回复 <strong>审核中用户</strong>: <i>该回复正在审核中。</i>
                {% endif %}

Related articles

How to correctly render Markdown content (including formulas, flowcharts) as HTML display in AnQiCMS?

AnQiCMS has always been committed to providing efficient and flexible solutions in content display, especially for the increasingly popular Markdown format in modern content creation, which includes complex content with mathematical formulas and flowcharts. AnQiCMS also provides a comprehensive support mechanism to ensure that these contents can be correctly parsed and beautifully presented on the web. To achieve the correct rendering of Markdown content (including formulas and flowcharts), it mainly involves two aspects: the first is the internal handling of Markdown text by the AnQiCMS system...

2025-11-08

How do custom fields of the content model (such as radio, checkbox, text) display on the front-end page?

AnQi CMS: Let the custom content model fields shine in the front-end When using AnQi CMS to manage website content, we often encounter such needs: the standard content structure can no longer fully meet the display of specific information.For example, a product page may need to display its "color options", "size range", or "stock status", etc.At this time, the flexible content model and custom field function of Anqi CMS are particularly important, as it allows us to expand content attributes based on the uniqueness of our business.

2025-11-08

How to dynamically display content on the AnQiCMS document list page through filtering conditions?

How to make users more efficiently find and browse content in website operation is the key to improving user experience and website value.Especially for document list pages, if a flexible filtering function can be provided, allowing users to dynamically adjust the display of content according to their needs, it will undoubtedly greatly enhance the interactivity and usability of the website.AnQiCMS with its flexible content model and powerful template tag features can easily meet this requirement.

2025-11-08

How does the inheritance mechanism of the category template affect the content display of the subcategory page?

The inheritance mechanism of AnQi CMS category templates: How to balance the consistency of page content and personalized displayAnQi CMS deeply understands this, and its inheritance mechanism of classification templates is specifically designed to help us cleverly solve this problem.

2025-11-08

How to display the user submitted comment form and its custom fields in AnQiCMS template?

In website operation, collecting user feedback and inquiries is an important link to improve service quality and understand user needs.AnQiCMS (AnQiCMS) provides a flexible and powerful message management function, allowing you to easily display a message form in the front-end template and support custom fields to meet the information collection needs of different business scenarios.To implement dynamic display of user submitted comment forms and custom fields in AnQiCMS templates, we mainly use a core tag: `guestbook`

2025-11-08

How to display the friend link list on the AnQiCMS front-end page?

Friendship links are a way for websites to recommend each other, not only can they increase the number of external links to the website, but also be beneficial for search engine optimization (SEO), but also provide visitors with more entry points to related resources, enhancing the user experience.AnQiCMS provides a very convenient function for us to manage and display friend links. Next, we will learn together how to set up friend links in AnQiCMS and display them on the website's frontend page.### One, manage the friendship link in AnQiCMS background In AnQiCMS, managing friendship links is very intuitive

2025-11-08

How to use AnQi CMS to realize personalized display of different content models (such as articles, products)?

AnQi CMS is an efficient and customizable content management system, one of its core advantages is the flexible content model.This provides website operators with great freedom, allowing us to design unique structures and display methods for various content types such as 'articles', 'products', etc., thus realizing the personalized presentation of website content.Next, we will delve into how to take advantage of the powerful functions of AnQi CMS to achieve personalized display of content models.Understanding the content model of Anqi CMS

2025-11-08

How to configure and display multilingual website content in AnQi CMS?

AnQiCMS is dedicated to helping users easily meet the needs of global content promotion. It has built-in multilingual support functions, allowing you to flexibly configure and display different language versions of website content.No matter if you want to provide translations for static text in templates or create independent language versions for articles, products, and other core content, AnQi CMS offers intuitive and powerful tools.Next, we will explore how to configure and display multilingual website content in Anqi CMS.### The First Part

2025-11-08