How to display a document's comment list in Anqi CMS template, including reply and pagination features?

Calendar 👁️ 57

In Anqi CMS, add a comment list to the document content, and enable reply and pagination features, which can greatly enhance the user interaction of the website.Users can express their opinions and engage in discussions about specific documents, which not only enriches the content ecosystem but also brings more vitality to the website.

One, display the comment list: the foundation of interaction

To display comments on the document page, it mainly depends on the built-in Anqi CMS.commentListLabel. This label helps us easily access the comment data associated with the current document.

First, we need to be in the document detail page template, usually{模型table}/detail.htmlOr a custom document template likedownload.htmlFind the appropriate location to place the comment area in the.

commentListThe core parameters of the tag include:

  • archiveIdThis is crucial, it specifies which document's comments to display. Usually, we would get the current document's ID.
  • typeThe type of the comment list is set to"list"When set, it will list comments in the specified quantity; set to"page"When set, it indicates that we want to enable pagination for the comment list, which willpaginationtag usage
  • limit: Controls the number of comments displayed per page or each time.
  • orderUsed to specify the sorting rule of comments, such as byid desc(Most recent comments first) orid asc(Oldest comments first).

This is a basic comment list code structure, which will loop to display comments and include some basic information:

{# 获取当前文档的ID,以便加载其评论 #}
{% archiveDetail currentArchiveId with name="Id" %}

<div class="comment-section">
    <h3>用户评论</h3>
    {% commentList comments with archiveId=currentArchiveId type="list" limit="10" order="id desc" %}
        {% for item in comments %}
            <div class="comment-item">
                <div class="comment-header">
                    <span class="comment-author">{{item.UserName}}</span>
                    <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
                </div>
                <div class="comment-content">
                    {# 判断评论状态,若在审核中则显示提示 #}
                    {% if item.Status != 1 %}
                        <p class="review-status">(评论正在审核中...)</p>
                    {% else %}
                        <p>{{item.Content}}</p>
                    {% endif %}
                </div>
            </div>
        {% empty %}
            <p class="no-comments">暂无评论,快来发表你的看法吧!</p>
        {% endfor %}
    {% endcommentList %}
</div>

In this example, we firstarchiveDetailThe tag obtained the current document'sIdand then passed it tocommentListofarchiveIdParameter.forLoop through each comment (item) and display the author, time, and content.item.Statusfield can be used to determine whether the comment has passed the review, so that different content can be displayed on the front end.

Second, integrate the reply function: make the discussion deeper

The interaction in the comment area is not just one-way comments; the reply function is the key to enhancing interaction depth. AnQi CMS'scommentListTags naturally support reply functions, throughitem.Parentfields can judge and display parent comments.

When a comment is a reply to another comment,item.ParentThis will include the complete data of the parent comment. We can use this feature to build a hierarchical display of replies.

{# 假设currentArchiveId已在上方获取 #}
<div class="comment-section">
    <h3>用户评论</h3>
    {% commentList comments with archiveId=currentArchiveId type="list" limit="10" order="id desc" %}
        {% for item in comments %}
            <div class="comment-item">
                <div class="comment-header">
                    <span class="comment-author">{{item.UserName}}</span>
                    <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
                </div>
                <div class="comment-body">
                    {# 如果是回复,显示父级评论内容 #}
                    {% if item.Parent %}
                        <blockquote class="reply-to">
                            回复 @{{item.Parent.UserName}}:
                            {% if item.Parent.Status != 1 %}
                                <p>(原评论正在审核中...)</p>
                            {% else %}
                                <p>{{item.Parent.Content|truncatechars:100}}</p>
                            {% endif %}
                        </blockquote>
                    {% endif %}
                    <div class="comment-content">
                        {% if item.Status != 1 %}
                            <p class="review-status">(评论正在审核中...)</p>
                        {% else %}
                            <p>{{item.Content}}</p>
                        {% endif %}
                    </div>
                </div>
                <div class="comment-actions">
                    <a href="javascript:;" class="reply-button" data-comment-id="{{item.Id}}" data-user-name="{{item.UserName}}">回复</a>
                    <a href="javascript:;" class="like-button" data-comment-id="{{item.Id}}">点赞 (<span class="vote-count">{{item.VoteCount}}</span>)</a>
                </div>
            </div>
        {% empty %}
            <p class="no-comments">暂无评论,快来发表你的看法吧!</p>
        {% endfor %}
    {% endcommentList %}
</div>

By adding ablockquoteElement to display the replied comment content and add the 'Reply' buttondata-comment-idanddata-user-nameProperties, so that subsequent through JavaScript to implement the click reply, automatically fill in the form reply object.

3. Smooth Browsing: Comment Pagination Functionality

When the number of comments is large, pagination is the key to maintaining page loading speed and user experience. Anqi CMS can do this throughcommentListoftype="page"Parameters andpaginationcooperation with tags, it can easily achieve comment pagination.

We willcommentListoftypethe parameter to"page"then use it externallypaginationtags to generate pagination navigation.

{# 假设currentArchiveId已在上方获取 #}
<div class="comment-section">
    <h3>用户评论</h3>
    {% commentList comments with archiveId=currentArchiveId type="page" limit="5" order="id desc" %}
        {% for item in comments %}
            <div class="comment-item">
                {# ... 评论内容及回复逻辑(同上) ... #}
                <div class="comment-header">
                    <span class="comment-author">{{item.UserName}}</span>
                    <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
                </div>
                <div class="comment-body">
                    {% if item.Parent %}
                        <blockquote class="reply-to">
                            回复 @{{item.Parent.UserName}}:
                            {% if item.Parent.Status != 1 %}
                                <p>(原评论正在审核中...)</p>
                            {% else %}
                                <p>{{item.Parent.Content|truncatechars:100}}</p>
                            {% endif %}
                        </blockquote>
                    {% endif %}
                    <div class="comment-content">
                        {% if item.Status != 1 %}
                            <p class="review-status">(评论正在审核中...)</p>
                        {% else %}
                            <p>{{item.Content}}</p>
                        {% endif %}
                    </div>
                </div>
                <div class="comment-actions">
                    <a href="javascript:;" class="reply-button" data-comment-id="{{item.Id}}" data-user-name="{{item.UserName}}">回复</a>
                    <a href="javascript:;" class="like-button" data-comment-id="{{item.Id}}">点赞 (<span class="vote-count">{{item.VoteCount}}</span>)</a>
                </div>
            </div>
        {% empty %}
            <p class="no-comments">暂无评论,快来发表你的看法吧!</p>
        {% endfor %}
    {% endcommentList %}

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

paginationlabel'sshowThe parameter controls the maximum number of page buttons displayed. It generates links such as “Home”, “Previous page”, “Numeric page numbers”, “Next page”, “End page”, and so on, the links of whichLinkProperties can be used directly.

4. Collect feedback: Comment submission form

With the comment list, it naturally needs a comment submission form. The comment submission form requires specificactionpaths and fields.

`twig {# Assuming currentArchiveId has been retrieved above #}

<h3>发表评论</h3>
<form method="post" action="/comment/publish" id="comment-form">
    <input type="hidden" name="return" value="html"> {# 后台返回html

Related articles

How to dynamically generate a custom field comment form with `guestbook` tag and adapt to different input types?

Managing website comments in Anqi CMS is a common requirement in daily operations, especially when we need to collect specific information, a flexible and customizable comment form becomes particularly important.Aqie CMS fully considers this requirement and provides a powerful `guestbook` tag, allowing us to easily dynamically generate a feedback form with custom fields and adapt to various input types.The power of the `guestbook` form label The core lies in the `guestbook` tag

2025-11-08

How to determine if the current navigation item is the current page in the `navList` loop?

In website operation, a clear navigation structure is crucial for improving user experience.A good navigation not only helps visitors quickly find the information they need, but also guides users through visual cues (such as highlighting the current page) so that they always know where they are.In AnQi CMS, implementing this feature is quite intuitive and efficient, which is due to its powerful template tag system.

2025-11-08

How to use the `navList` tag to create a navigation bar with submenus in the Anqi CMS template?

In AnQi CMS template development, building a functional and user-friendly navigation bar is one of the core tasks of website frontend development.Especially when navigation needs to include multi-level sub-menus, the `navList` tag provided by Anqi CMS can help us efficiently meet this requirement.Understanding the core role of the `navList` tag The `navList` tag is a tool specifically used in the Anqi CMS template to retrieve website navigation data and display it on the page.

2025-11-08

How to display documents under the current category using the `categoryList` tag without including documents from subcategories?

When building a website with Anq CMS, we often encounter such a need: on a category page, we want to display only the documents that belong to the current category, and not mix in the document content of its subcategories.This is particularly important in scenarios where the content structure is clear and avoids redundancy.Today, let's discuss in detail how to accurately achieve this goal through the template tags of Anqi CMS. ### Understanding AnQiCMS Classification and Document Relationship AnQiCMS has always fully considered the flexibility of content hierarchy from the beginning of its design.A category can have subcategories

2025-11-08

How to judge whether the comment is under review and display it conditionally using the `commentList` tag?

In website operation, comments are an important element in enhancing user interaction and community vitality.However, it is an indispensable link to review the comments submitted by users to ensure the health and quality of the website content.How can we flexibly display these comments in AnQi CMS, especially when they are still in the review stage, which has become a concern for many operators.It's good that AnQi CMS template tag system provides us with strong control, especially the `commentList` tag, which can help us easily implement conditional display of comments.

2025-11-08

How to create a customizable pagination component for the document list in Anqi CMS template?

It is crucial to display and manage document lists efficiently when building a content-rich website.Especially for sites with a large amount of content, a well-designed, feature-complete pagination component can not only greatly improve user experience but also optimize the website's SEO performance, helping search engines to better crawl and index content.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag features, allows us to easily create highly customizable pagination components for document lists.

2025-11-08

How to get the current page number, total number of pages, and home/last page links for the `pagination` tag?

AnQiCMS (AnQiCMS) is a powerful content management system that provides flexible and diverse ways to display content when building a website.Among them, the pagination function is crucial for list pages with a large amount of content, as it not only improves the user experience but also optimizes the website performance.Proficiently use the `pagination` tag, which can help us accurately control the display logic of pagination, thereby creating a more user-friendly and professional website.

2025-11-08

How to list all documents under a specific tag in AnQi CMS template and support pagination?

In a content management system, effectively organizing and displaying articles is the key to improving user experience.When content is categorized through tags, we often need to list all the articles under a specific tag on a page, and to maintain the cleanliness and loading speed of the page, pagination functionality also becomes indispensable.Strong and flexible template tags provided by AnQi CMS make this requirement easy to achieve.

2025-11-08