How to display the AnqiCMS comment list on the front page and support pagination and parent-child comment display?

Calendar 👁️ 72

The Anqi CMS provides a convenient comment function for website content interaction, allowing visitors to express their opinions on articles, products, and other content.For website operators, how to clearly display these comments on the website front-end and provide user-friendly pagination and parent-child comments (that is, reply function) is a key link to improve user experience.Below, let's discuss how to achieve this goal in Anqi CMS.

Understanding the core elements of the comment function

In AnQi CMS, the comment feature is built around documents (such as articles, products, etc.).Each comment is associated with a specific document ID.

  • Document ID (archiveId): This tells the system which article or product comments we want to retrieve.
  • Comments list tag (commentList): Used to retrieve comment data from the database.
  • Pagination tag (pagination): Handling page jump when the number of comments is large.
  • Parent-child comment structure (item.Parent): Differentiating between the main comment and the reply to the main comment, implementing nested display.

Step 1: Get the document ID of the current page

Generally, comment lists are displayed on the detail page of specific documents. Therefore, we need to first obtain the unique identifier of the current document - the document ID. Anqi CMS providesarchiveDetailLabel to get the document details, which includes the document ID.

You can use the template on the document detail page (for example)archive/detail.html) to obtain the current document ID in the following way:

{% archiveDetail currentArchiveId with name="Id" %}

Here, we assign the current document ID to a variablecurrentArchiveIdso that it can be used in subsequent operationscommentListin the tag.

Step two: Display the basic comment list

With the document ID, we can usecommentListThe tag retrieves and displays comments. This tag is very flexible, allowing us to control the sorting, display quantity, and list type of comments.

To display a basic comment list, we can specifyarchiveIdfor the just obtainedcurrentArchiveIdAnd, totypeis set tolist, and setlimitto control the number of comments displayed per page (here we assume it is set to 10 comments).

<div class="comments-section">
    <h3>用户评论</h3>
    {% commentList comments with archiveId=currentArchiveId type="list" limit="10" %}
        {% for item in comments %}
            <div class="comment-item">
                <p class="comment-meta">
                    <strong>{{ item.UserName }}</strong> 发表于
                    <span>{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
                </p>
                <div class="comment-content">
                    {% if item.Status != 1 %}
                        <p class="moderating-tip">此评论正在审核中,稍后可见。</p>
                    {% else %}
                        <p>{{ item.Content }}</p>
                    {% endif %}
                </div>
                <div class="comment-actions">
                    <a href="javascript:;" class="reply-btn" data-id="{{ item.Id }}" data-user="{{ item.UserName }}">回复</a>
                    <a href="javascript:;" class="praise-btn" data-id="{{ item.Id }}">赞(<span class="vote-count">{{ item.VoteCount }}</span>)</a>
                </div>
            </div>
        {% empty %}
            <p>目前还没有评论,快来发表你的看法吧!</p>
        {% endfor %}
    {% endcommentList %}
</div>

In this example, we traversedcommentsthe list, displaying the username, posting time, comment content, and added comment status judgment (item.Status), in order to give users a friendly reminder during comment review. At the same time, we also added 'reply' and 'like' buttons for subsequent interactions.

Step 3: Implement pagination for the comment list

When there are many comments, loading them all at once can affect the performance of the page. At this point, pagination becomes particularly important. To implement pagination, we need tocommentListlabel'stypeparameters fromlistchanged topage, then combinepaginationtags to generate pagination navigation.

First, modifycommentListTags:

{% commentList comments with archiveId=currentArchiveId type="page" limit="10" %}
    {# 评论内容展示与之前类似 #}
{% endcommentList %}

Next, incommentListlabel's{% endcommentList %}After, addpaginationTags to generate pagination links:

<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 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}}">{{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>
        <p class="pagination-info">共 {{pages.TotalItems}} 条评论,当前第 {{pages.CurrentPage}} / {{pages.TotalPages}} 页</p>
    {% endpagination %}
</div>

paginationTags will generate home, previous page, specific page number, next page, and end page links based on the current comment list.show="5"The parameter indicates that up to 5 page number buttons can be displayed.item.IsCurrentIt can help us add a highlight style to the current page number.

Step 4: Implement nested display of parent-child comments.

The parent-child comment (i.e., reply) function is an important embodiment of the interactivity in the comment area. Anqi CMScommentListtags are provided in each comment itemitemin the form of a tagParentIf the current comment is a reply to another comment,item.Parentit will contain the complete information of the replied comment. We can use this to design nested comment styles.

To implement the display of parent-child comments, we can iterate through in the loopcommentswhen, judgeitem.ParentDoes it exist. If it exists, it means it is a reply, and we can display its content nested and indicate which comment it is replying to.

`twig

<h3>用户评论</h3>
{% commentList comments with archiveId=currentArchiveId type="page" limit="10" %}
    {% for item in comments %}
        <div class="comment-item {% if item.Parent %}comment-reply{% endif %}">
            <p class="comment-meta">
                <strong>{{ item.UserName }}</strong>
                {% if item.Parent %}
                    回复 <strong>{{ item.Parent.UserName }}</strong>
                {% endif %}
                发表于
                <span>{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
            </p>
            <div class="comment-content">
                {% if item.Status != 1 %}
                    <p class="moderating-tip">此评论正在审核中,稍后可见。</p>
                {% else %}
                    {% if item.Parent and item.Parent.Status == 1 %}
                        <blockquote class="reply-quote">
                            <p>{{ item.Parent.Content|truncatechars:100 }}</p>
                        </blockquote>
                    {% endif %}
                    <p>{{ item.Content }}</p>
                {% endif %}
            </div>
            <div class="comment-actions">
                <a href="javascript:;" class="reply-btn" data-id="{{ item.Id }}" data-user="{{

Related articles

How to display the document list associated with a specific Tag of AnqiCMS on the front page?

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website.The AnqiCMS Tag (tag) feature is exactly for this purpose.By cleverly using Tag, we can not only provide users with more accurate content navigation, but also make search engines better understand the structure of the website content. This article will focus on how to clearly and effectively display the document list associated with a specific Tag in AnqiCMS on the front page of a website.###

2025-11-09

How to display detailed information of a specific AnqiCMS Tag on the front page, such as description and Logo?

AnqiCMS as an efficient content management system not only provides rich content publishing and management functions, but also provides great flexibility for the display of front-end pages.In website operation, properly using tags (Tag) can effectively enhance the organization of content, user experience, and search engine optimization (SEO).When a user browses to a specific tag, if the page can directly display the detailed information of the tag, such as its description and exclusive Logo, it will undoubtedly greatly enhance the professionalism and attractiveness of the page.Next, we will explore how to use the AnqiCMS front page

2025-11-09

How to display the AnqiCMS document Tag list on the front page and support filtering by letter or category?

In a content management system, a tag (Tag) is a powerful tool that helps us organize content more flexibly and improve the efficiency of users in finding relevant information.AnQiCMS as an efficient enterprise-level content management system naturally also deeply integrates powerful tag features.If you are hoping to display a list of document tags on the website front end and allow users to filter by letter or category, this article will provide you with a comprehensive guide.

2025-11-09

How to implement the AnqiCMS document parameter filtering function on the front page to help users quickly locate content?

How to help users quickly find the information they are interested in on increasingly rich content websites is a crucial operational challenge.Users often need to filter content based on specific conditions rather than browsing aimlessly.AnqiCMS provides a powerful document parameter filtering function that allows you to easily achieve this goal on the front page, greatly enhancing user experience and content discoverability.

2025-11-09

How to build and display AnqiCMS's message form on the front page, supporting custom fields and captcha?

In website operation, establishing effective interaction with visitors is a key step to improve user experience and collect valuable feedback.Anqi CMS knows this point well, therefore it provides us with a powerful and flexible feedback form function, which not only supports basic feedback collection but also allows for easy customization of fields and captcha, making the website's interactive module efficient and secure.Next, we will delve into how to build and display a fully functional comment form on the front page of Anqi CMS, supporting custom fields and captcha, thereby better serving our users.

2025-11-09

How to display the AnqiCMS backend management's friend links on the front page and control the Nofollow attribute?

In website operation, friendship links are an important means to enhance website authority, attract traffic, and strengthen industry associations.However, how to effectively manage these links, especially in terms of search engine optimization (SEO), ensuring that they can play a positive role while not causing negative effects on their own website, is a concern for many operators.AnqiCMS as a content management system dedicated to providing efficient and customizable solutions offers very convenient and flexible tools in this regard.

2025-11-09

How to implement pagination navigation in AnqiCMS templates and customize the display of page numbers and style?

In a content management system, especially when a website carries a large amount of articles, products, or other list information, reasonable pagination navigation is the key to improving user experience and facilitating content browsing.It can not only help visitors quickly find the information they need, but also avoid the slow loading caused by too long single-page content, and it is also very beneficial for search engine optimization (SEO).AnqiCMS provides a powerful and flexible template tag set, allowing you to easily implement pagination functionality on your website and customize its display style and appearance as needed.### Enable pagination feature: Starting from the list tag At

2025-11-09

How does the AnqiCMS template use if/else tags for conditional judgments to dynamically display different content?

In website content operation, we often need to flexibly display different content modules or styles based on different conditions to enhance user experience and page interactivity.AnqiCMS (AnqiCMS) provides powerful template tag features, among which the `if/else` conditional judgment tags are the core tools to achieve this goal.By it, we can easily make the website content come to life according to specific rules, no longer monotonous static display.### AnqiCMS template basic conditional judgment: `if`

2025-11-09