How to correctly display user comments and their review status in the AnQiCMS comment list?

Calendar 👁️ 83

In AnQiCMS, managing and displaying user comments, especially their review status, is a very practical feature in content operation.It not only helps us maintain community order, but also allows for flexible control over the presentation of website content, ensuring the quality and compliance of published content.Next, let's take a detailed look at how to properly display user comments and their review status in your website comment list.

Core Feature: Comment List Invocation

To display user comments on the website page, we need to rely on the powerful template tag system of AnQiCMS. Among them,commentListTags are specifically designed for this purpose. Typically, we add a comment area at the bottom of the document details page (for example, article, product page).

UsecommentListWhen labeling, you first need to specify the document ID associated with the comment. This ID is usually obtained through the current document information on the page (for example, on the article detail page, we can obtain it througharchive.IdPass ()to transfer. At the same time, you can choose the display type of the comment list, for exampletype="list"Used to display a fixed number of comments at one time, ortype="page"Used for pagination display, which can effectively improve page loading speed and user experience when there are many comments.limitThe parameter allows you to control the number of comments loaded per page or each time.

Here is a basiccommentListexample of tag usage, it will retrieve the comment list of the current document:

{% commentList comments with archiveId=archive.Id type="list" limit="6" %}
    {% for item in comments %}
    <div class="comment-item">
        <span class="comment-user">{{item.UserName}}</span>
        <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
        <p class="comment-content">{{item.Content}}</p>
    </div>
    {% endfor %}
{% else %}
    <p>暂无评论,快来发表你的看法吧!</p>
{% endcommentList %}

In this example,archive.Idrepresents the document ID of the current page.commentsThis is the variable name defined for the comment list data, you can accessforthrough the loopitemto access the specific information of each comment.stampToDateLabels can help us format timestamps into readable dates and times.

Control comment status: Display review information correctly.

The review status is a key link in content management. AnQiCMS providesStatusfield, whose value is1indicating that the comment has been reviewed and can be displayed normally, while0It indicates that the comment is under review. Through this field, we can flexibly handle the display of pending review comments on the front-end page.

In general, we do not display the full content of comments under review directly, but provide a prompt information, such as 'The content is being reviewed.'For reply-type comments, we also need to consider the review status of the parent comment.

The following is an improvement on the previous example code, adding handling for comment review status and reply comments.

`twig {% commentList comments with archiveId=archive.Id type=“list” limit=“6” %}

{% for item in comments %}
<div class="comment-item">
    <div class="comment-meta">
        <span class="comment-user">
            {% if item.Status != 1 %}
                <!-- 评论待审核时,用户名可截断或显示为匿名 -->
                审核中:{{item.UserName|truncatechars:6}}
            {% else %}
                {{item.UserName}}
            {% endif %}
        </span>
        {% if item.Parent %}
            <span class="reply-indicator">回复</span>
            <span class="comment-parent-user">
                {% 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-body">
        {% if item.Parent %}
            <blockquote class="reply-quote">
                {% if item.Parent.Status != 1 %}
                    <p class="pending-quote-message">该内容正在审核中:{{item.Parent.Content|truncatechars:15}}</p>
                {% else %}
                    <p>{{item.Parent.Content|truncatechars:100}}</p>
                {% endif %}
            </blockquote>
        {% endif %}
        {% if item.Status != 1 %}
            <p class="pending-message">该内容正在审核中:{{item.Content|truncatechars:15}}</p>
        {% else %}
            <p>{{item.Content}}</p>
        {% endif %}
    </div>
    <div class="comment-actions" data-id="{{item.Id}}" data-user="{{item.UserName}}">
        <a class="action-item vote-comment">赞

Related articles

How does AnQiCMS ensure that the HTML content output through the `safe` filter is secure and correctly parsed and displayed on the front end?

In website operation, we often need to display user input or HTML content generated by a rich text editor.How to ensure that these dynamic contents are displayed correctly and avoid potential security risks is a challenge that every content management system must face.AnQiCMS as a Go language CMS that focuses on security has a mature mechanism in this aspect, especially the `safe` filter it provides, which plays a key role in ensuring the security and correct parsing of front-end content. ### Default security considerations: Why escape automatically?

2025-11-09

How to set up an independent display layout and elements for the single page of AnQiCMS, such as the 'About Us' page?

In AnQiCMS, setting up an independent display layout and elements for single pages like "About Us" can make the website content more distinctive and professional.AnQiCMS with its flexible template engine and modular design makes this process intuitive and efficient.Why do you need a custom layout for a single page?

2025-11-09

How to flexibly call and display the value of the 'Content Model Custom Field' in the AnQiCMS frontend page?

AnQi CMS excels in content management, especially its flexible content model and custom field features, which greatly facilitates the construction of personalized websites for us.The content of a website is often not just the title and text, but we may also need various additional information such as the author of the article, the source of publication, product specifications, event location, and floor area.These custom fields are like a 'personal filing cabinet' for content, allowing us to tailor the required attributes for each content type according to business needs.

2025-11-09

How to correctly display the filing number and copyright information at the bottom of the AnQiCMS website and ensure automatic year update?

Information at the bottom of the website, such as filing numbers and copyright statements, may seem trivial, but it is an important manifestation of the website's professionalism, legal compliance, and brand trust.For operators, correctly displaying this information and ensuring that the year can be automatically updated is not only convenient but also avoids the trouble of manual modification every year.In AnQiCMS, achieving this goal is very direct and flexible.

2025-11-09

Does AnQiCMS provide a convenient tag to display the website logo and name, and support multi-site calls?

In the process of managing and operating a website, the brand image of the website - Logo and website name - is undoubtedly the core identification.They not only represent the identity of the website, but also directly affect users' perception of the brand.For a system like AnQiCMS that is committed to providing an efficient content management solution, how conveniently to display this key information, and to support flexible calls under a multi-site environment, is an important standard to measure its usability and powerful features.AnQiCMS' design concept in this aspect is centered around 'convenience' and 'flexibility'

2025-11-09

How to accurately format the display of the article's publication and update timestamps in AnQiCMS templates?

In website content operation, clearly displaying the publishing and update time of articles is crucial for improving user experience, providing timeliness information of content, and optimizing search engine indexing.AnQiCMS provides a powerful and flexible timestamp formatting function in the template, allowing us to convert the original timestamp data into user-friendly date and time display according to specific needs.

2025-11-09

How does AnQiCMS dynamically generate and display breadcrumb navigation and control whether to include the current page title?

When building a user-friendly website, breadcrumb navigation plays an indispensable role.It not only can intuitively display the user's current position on the website, avoid getting lost, but also optimize the website structure, which is very beneficial for search engine optimization (SEO).For users of AnQiCMS, utilizing its powerful template tag system to dynamically generate and flexibly control breadcrumb navigation is the key to improving the website experience.

2025-11-09

How to configure AnQiCMS so that it displays correctly as an independent mobile site on mobile devices?

In AnQiCMS, to provide a better user experience for mobile device users, we can configure the website to display independent site content on mobile devices.This independent operation model for PC and mobile terminals not only helps to design and optimize for different devices in a refined manner, but also can improve the SEO performance of mobile terminals in specific scenarios.AnQiCMS provides us with a variety of website display modes, including the "PC+Mobile independent site" mode, which is the basis for realizing independent content display on the mobile end.Next, we will step by step discuss how to configure AnQiCMS

2025-11-09