How does AnQiCMS display the comment list on article or product detail pages?

Calendar 👁️ 70

In website operation, user interaction is an important factor in enhancing content value and website activity.The comment feature acts as a bridge for users to directly communicate with content, not only enriching the page content, bringing unique UGC (User Generated Content) to the website, but also enhancing the community atmosphere and having a positive effect on search engine optimization (SEO).AnQiCMS (AnQiCMS) offers a powerful and flexible comment list display feature that allows you to easily display user comments on articles or product detail pages and manage them effectively.

Understand the comment mechanism of AnQiCMS

The comment feature of AnQi CMS is designed to be very practical.In the content management backend, you can manage comments uniformly, including review, delete, and other operations.On the front-end page, the display of comments is achieved through concise and clear template tags.This means that you do not need to delve into complex code, just use the specific tags in the corresponding template file to control the display of comments.

The display of the comment list mainly depends oncommentListTag.This tag can flexibly extract comment data associated with a specific article or product from the database and display it on the web page.It supports various parameter configurations to meet different display requirements, such as specifying the article or product to which the comment belongs, setting the sorting method of the comments, and deciding whether the comment list is displayed in pagination or listed in full.

Display the comment list in the template

To display the comment list on the article or product detail page, you first need to find the corresponding detail page template file. Anqi CMS templates follow the Django template engine syntax, and the files are usually located at/templateUnder the directory, the detail page template may be named{模型table}/detail.htmlor a similar structure.

In the detail page template, you can usecommentListtags to call comment data. The most core parameter isarchiveIdIt is used to specify the article or product ID of the comment. Usually, this ID is automatically obtained from the current page's article or product details, and you can also pass it explicitly.

For example, a basic code to display a comment list might look like this:

{# 假设当前页面是文章详情页,且已通过archiveDetail标签获取了当前文章的ID #}
{% archiveDetail currentArchive with name="Id" %}
<div class="comments-section">
    <h3>用户评论 ({{ currentArchive.CommentCount }})</h3>
    {% commentList comments with archiveId=currentArchive type="list" limit="10" order="id desc" %}
        {% 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>
                <span class="time">{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
            </div>
            <div class="comment-content">
                {% if item.Parent %}
                <blockquote class="reply-to">
                    回复 @{{ item.Parent.UserName }}:
                    {% 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>
            {# 如果需要点赞功能,可以在这里添加相关的HTML和JS逻辑 #}
            <div class="comment-actions">
                <a class="praise-btn" data-id="{{ item.Id }}">赞 ({{ item.VoteCount }})</a>
                <a class="reply-btn" data-parent-id="{{ item.Id }}" data-username="{{ item.UserName }}">回复</a>
            </div>
        </div>
        {% empty %}
        <p>暂无评论,快来发表您的看法吧!</p>
        {% endfor %}
    {% endcommentList %}
</div>

In this example,archiveIdSet tocurrentArchiveID.type="list"Means only a specified number of comments are listed,limit="10"Limited the number of displayed comments,order="id desc"Then let the latest comments be displayed at the top.

It is worth noting that each commentitemhasStatusField, used to indicate whether the comment has been reviewedStatus = 1Means it has been approved,0Indicates under review). To provide a better user experience, you can judge by whetherStatusThe field displays a "under review" prompt instead of directly showing the unreviewed content. Additionally, if a comment is a reply to another comment,item.ParentThe field contains information about the parent comment, allowing you to clearly display the comment hierarchy.

Paginated display of comment list

When there are many comments, loading all comments at once may affect page loading speed and user experience. The Anqi CMS'scommentListTag supporttype="page"parameters, can be combinedpaginationtags can be used to implement comment pagination.

While usingtype="page"after,commentListThe tag intelligently handles the current page number and total page number information, andpaginationThe tag outputs pagination navigation.

{# 假设当前页面是文章详情页,且已通过archiveDetail标签获取了当前文章的ID #}
{% archiveDetail currentArchive with name="Id" %}
<div class="comments-section">
    <h3>用户评论</h3>
    {% commentList comments with archiveId=currentArchive type="page" limit="5" order="id desc" %}
        {% 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>
                    <span class="time">{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
                </div>
                <div class="comment-content">
                    {% if item.Parent %}
                    <blockquote class="reply-to">
                        回复 @{{ item.Parent.UserName }}:
                        {% 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="praise-btn" data-id="{{ item.Id }}">赞 ({{ item.VoteCount }})</a>
                    <a class="reply-btn" data-parent-id="{{ item.Id }}" data-username="{{ item.UserName }}">回复</a>
                </div>
            </div>
        {% empty %}
        <p>暂无评论,快来发表您的看法吧!</p>
        {% endfor %}
    {% endcommentList %}

    {# 分页导航 #}
    <div class="pagination-section">
        {% pagination pages with show="5" %}
            <ul>
                {% if pages.FirstPage %}
                <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                    <a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
                </li>
                {% endif %}
                {% if pages.PrevPage %}
                <li class="page-item">
                    <a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a>
                </li>
                {% endif %}
                {% for pageItem in pages.Pages %}
                <li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
                    <a href="{{ pageItem.Link }}">{{ pageItem.Name }}</a>
                </li>
                {% endfor %}
                {% if pages.NextPage %}
                <li class="page-item">
                    <a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a>
                </li>
                {% endif %}
                {% if pages.LastPage %}
                <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                    <a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
                </li>
                {% endif %}
            </ul>
        {% endpagination %}
    </div>
</div>

Through the pagination feature, even with a large number of comments, the page can maintain neatness and loading efficiency.

Submit comment form

After the comment list is displayed, it is usually necessary to provide a form for users to submit new comments. The submission target address of the comment form is/comment/publish. The form needs to include several key fields, such asarchive_id(ID of the article/product the comment belongs to),user_name(Name of the commenter),content(Comment content), optional),parent_id(If this is a reply to a specific comment).

To prevent spam comments, you can also enable the comment captcha feature in the background. Once enabled, you need to integrate the captcha display and verification logic into the comment form, which can be done bytag-/anqiapi-other/167.htmlThe provided JavaScript code snippet can be easily implemented.

Summary

Anqi CMS passedcommentListandpaginationThe template tags provide an efficient and flexible solution for displaying comments lists on article or product detail pages.From simple comment listing to pagination display, to the presentation of comment levels and review status, these features can help you build a website with rich interactivity and content.Reasonably utilize these features to greatly enhance user engagement and effectively manage user-generated content.


Frequently Asked Questions (FAQ)

1. How to enable or disable the comment function on the article/product detail page?

The overall enable or disable of the comment function is usually set in the Anqi CMS backend.You can log in to the backend, find the relevant options under "Function Management" and "Content Comment Management".Here, you may find global settings that control whether users are allowed to comment on articles or products.

2. Do user submitted comments need to be reviewed before displaying on the front page?

Yes, Anqi CMS provides a comment review mechanism. When displaying the comment list, as shown in the article, there is aStatusfield (1indicating the review has passed,0Reviewing...This means that newly submitted comments are set to pending review by default, and they can only be publicly displayed on the front end after passing the review from the back end.This helps website administrators control content quality and avoid inappropriate speech.

How to add 'like' or 'reply' and other interactive features to the comment list?

For each item in the comment list,itemIn Chinese, you can add custom HTML elements (such as buttons or links) to implement the "like" and "reply" functions. For "like", it usually requires JavaScript to/comment/praiseThe interface sends a POST request and passes the comment'sid. For 'reply', you can dynamically generate a reply form or fill in an existing form using JavaScript.parent_idanduser_nameThe field indicates which comment is being replied to, thus enabling the nesting and interaction of comments.

Related articles

How to dynamically display the breadcrumb navigation of the current page in AnQiCMS template?

Build a user-friendly, SEO-friendly website in AnQiCMS, breadcrumb navigation is an indispensable element.It can clearly show the user's current location, help the user quickly backtrack, and provide valuable website structure information for search engines.AnQiCMS's powerful template engine provides a simple and efficient way to dynamically generate these navigation paths.AnQiCMS's template system adopts syntax similar to the Django template engine, which makes it very easy for content developers to control the display of page content through tags and variables

2025-11-08

How to build and display a multi-level website navigation menu in AnQiCMS?

In website operation, a clear and intuitive navigation menu is the core of user experience, it can not only guide visitors to quickly find the information they need, but is also an important part of website structure and SEO optimization.AnQiCMS as an efficient enterprise-level content management system, provides flexible and powerful navigation menu construction and display functions, helping you easily manage the hierarchical structure of your website.**One, build navigation menu in AnQiCMS background** The first step in building a multi-level navigation menu is to centrally manage it in the AnQiCMS background

2025-11-08

How to control the thumbnail size and cropping method in AnQiCMS template?

When building and operating a website, the presentation of images often directly affects user experience and the professionalism of the site.AnQiCMS (AnQiCMS) fully understands this and provides users with a powerful and flexible thumbnail control function, allowing you to precisely manage the display of images on the website front-end according to your actual needs.This article will introduce in detail how to achieve fine-grained control over the thumbnail size and cropping method of images in Anqi CMS through backend settings and template calls.### Backend sets thumbnail rules unification

2025-11-08

How does AnQiCMS automatically convert uploaded images to WebP format to speed up loading?

In website operation, the speed of image loading is often a key factor affecting user experience and search engine ranking.A lightweight, high-quality image can make a website stand out among competitors.AnQiCMS knows this need and has built-in functionality to automatically convert images to WebP format, making image optimization unprecedentedly simple.

2025-11-08

How to call and display the form fields submitted by users in the AnQiCMS template?

AnQi CMS provides a flexible mechanism to handle the interactive content of websites, among which the message form is an important bridge for communication with users.When we need to collect diverse information from users, we often create custom message fields.How to accurately call and display these custom form fields configured in the backend template on the website's frontend, which is the key to achieving personalized user experience.In AnQiCMS, the display of the message form fields mainly depends on the use of template tags.

2025-11-08

How to display the Tag list associated with the article in AnQiCMS?

In AnQiCMS, effectively managing and displaying the tag (Tag) list of articles can not only help with content organization but also significantly improve the internal link structure and search engine optimization (SEO) effect of the website.Labels as a flexible classification method can link articles across categories and themes, providing users with a richer browsing path. ### Manage and create article tags in the background First, understanding how to add and manage article tags in the AnQiCMS background is fundamental.

2025-11-08

How to retrieve and display the friend link list in AnQiCMS template?

In website operation, friendship links are an important factor in improving website authority, increasing external traffic, and optimizing user experience.AnQiCMS (AnQiCMS) is well aware of this, and therefore provides a convenient friend link management function in system design, and supports flexible calling and display in templates.This article will provide a detailed introduction on how to retrieve and display the friend link list in your AnQiCMS template.### Management of friendship links: Starting from the background Before starting the template call, make sure that your website's background has configured the friendship links

2025-11-08

How to display the document list under a specific Tag in AnQiCMS?

In AnQiCMS, tags (Tag) are a powerful and flexible way to organize content, allowing you to associate documents in multiple dimensions without relying on traditional hierarchical classification structures.When you want to display all documents under a specific topic or keyword, it is particularly important to show the document list under a specific tag.This not only helps visitors find the content they are interested in faster, but also effectively improves the internal link structure and SEO performance of the website.

2025-11-08