How to get and display the comments made by users on the content for the comment list label `commentList`?

Calendar 👁️ 98

In today's digital world, websites are not just platforms for displaying information, but also spaces for user interaction and communication.When users are able to express their opinions and raise questions about the content, the vitality of the website will be greatly enhanced.AnQi CMS understands this point, therefore it provides a powerful and flexible comment management function, including the "comment list tag"commentListIt is the key bridge connecting content and user feedback.

Imagine that you have published an engaging article or an innovative product, and users can't wait to share their thoughts after reading it.As a website operator, you naturally want these valuable comments to be presented clearly and in order below the content.AnQi CMS'scommentListTags were born for this, allowing you to easily obtain and display user comments on your website content, making interaction accessible.

Deep understandingcommentListTag

commentListThe tag is a core feature provided by the Anqi CMS template engine, which mainly serves to retrieve and display all comments related to specific content (such as articles, products).Whether it is necessary to display the latest comments, hot comments, or add a comment section to the content detail page, this tag can meet your needs.

To usecommentListYou usually introduce it in the content detail template (such as the article detail pagearchive/detail.html). Its basic structure is as follows, you will assign the obtained comment data to a variable (such ascommentsThen, by looping through this variable, each comment is displayed one by one:

{% commentList comments with archiveId=archive.Id type="list" limit="6" %}
    {# 在这里,您将循环输出每条评论的详细信息 #}
{% endcommentList %}

In this code block,archive.IdIt usually represents the content ID of the current page,type="list"Means to get comments in a list form,limit="6"It limited the display of six comments each time.

Flexible control over the acquisition and display of comments.

commentListTags provide various parameters, allowing you to finely control the way comments are acquired:

  • archiveIdThis is the most important parameter, it specifies the content ID of the comments you want to retrieve. For example,archiveId="1"Will retrieve all comments for the content with ID 1. If you do not specify this parameter on the content detail page (such as the article detail page), AnQi CMS will intelligently automatically retrieve the content ID of the current page, which is very convenient.
  • typeDetermines the display style of the comment list. When set to"list"When, the tag will return the specified number of comments; whereas set to"page"It will return a comment list containing pagination information, which you can combinepaginationtag to achieve the pagination display of comments.
  • limitUsed to control the number of comments obtained each time. For example,limit="10"The latest 10 comments will be displayed. If you need more advanced offset control, you can use"2,10"This format indicates that 10 comments starting from the second one are to be retrieved.
  • order: Defines the sorting method of comments. You can choose."id desc"(Sorted by ID in reverse order, usually the latest comments are at the top) or"id asc"(Sorted by ID in ascending order, oldest comments first).
  • siteIdIf you have enabled the multi-site management feature of Anqi CMS and want to call comment data from other sites, you can specify the site ID through this parameter.

Detailed fields of comment data

Upon passingcommentListAfter obtaining the comment data, you can access various fields of each comment in the loop to build the comment display area.itemVariable (infor item in commentsdefined) will carry the details of each comment:

  • Id: The unique ID of the comment.
  • ArchiveId: The ID of the content to which the comment belongs.
  • UserName: The name of the user who posted the comment.
  • Content: The specific content of the comment.
  • ParentId: If this is a reply comment, this field will store the ID of the parent comment.
  • ParentThis is a very practical field, it directly contains the complete data object of the superior comment.This allows you to easily build multi-level conversation threads, known as 'building up' comments.
  • Status: Review status of the comment.1It usually means the review has been approved and displayed,0It means the review is in progress. When displaying comments, you should decide whether to show the comment content based on this status.
  • VoteCountThe number of likes on comments, which can be used to implement the comment liking function.
  • CreatedTimeThe posting time of comments (timestamp format). You need to combinestampToDateThe filter formats it into a readable date and time.

For example, display the username, content, and time of the comment:

{% commentList comments with archiveId=archive.Id type="list" limit="6" %}
    {% for item in comments %}
    <div>
      <div>
        <span>{{item.UserName}}</span>
        <span>于 {{stampToDate(item.CreatedTime, "2006-01-02 15:04")}} 评论道:</span>
      </div>
      <div>
        {% if item.Status == 1 %}
          {{item.Content}}
        {% else %}
          该内容正在审核中。
        {% endif %}
      </div>
    </div>
    {% endfor %}
{% endcommentList %}

Build a paged comment list

When your content has a large number of comments, pagination becomes very necessary. It willcommentListoftypethe parameter to"page"Then, combined with Anqi CMS'spaginationtags, you can easily achieve an elegant pagination effect.

First, incommentListRetrieve pagination data:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 评论列表内容 #}
{% endcommentList %}

Then, incommentListUse below the tag,paginationRender pagination navigation with the tag:

<div>
    {% pagination pages with show="5" %}
        {# 渲染分页链接,如首页、上一页、数字页码、下一页、尾页等 #}
        <ul>
            <li>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</li>
            <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
            {# ...其他分页链接... #}
        </ul>
    {% endpagination %}
</div>

In this way, users can easily browse all comments without feeling stuck due to too much content on a single page.

Comment submission and interaction

In addition to displaying comments, Anqi CMS also provides convenient interfaces for handling user submitted comments and likes:

  • Submit CommentYou can create an HTML form and submit itactionPoint to/comment/publish. The form must includearchive_idContent ID,user_name(Username),content(Comment content), if you want to implement a reply function, you can also addparent_idField. To prevent spam comments, it is recommended to enable comment captcha in the background and integrate captcha display in the form (refertag-/anqiapi-other/167.htmlto the instructions).
  • Comment Liking: Anqi CMS allows you to direct/comment/praiseAddress to send POST requests to implement comment liking. You need to pass the comment'sidAs an argument. Typically, this is done asynchronously using JavaScript to provide a smooth user experience.

Summary

commentListTags are an indispensable part of Anqi CMS content operation, helping you build an active and orderly comment interaction area on your website with its concise syntax and powerful functions.From basic comment display to complex pagination and hierarchical replies, to the submission and liking of comments, Anqi CMS provides a clear implementation path, allowing your content to truly resonate with users.


Frequently Asked Questions (FAQ)

1. How to ensure the quality of comment content and prevent spam?

The AnQi CMS provides a comment review mechanism and captcha feature to help you manage comment quality. You can determine whether a comment has been approved by checking theStatusfield in the comment data (Status = 1indicate pass).In the template,you can use it according toStatusField to decide whether to directly display comments or show the prompt "Content is under review". In addition, enable comment captcha in the background "Function Management" and integrate the captcha code into the comment submission form (refer totag-/anqiapi-other/167.htmlDocuments), it can effectively prevent automated spam comments.

2. Can I display reply comments in the comment list to form a conversation thread?

Of course you can.commentListThe tag returns a comment data that includes oneParentfield. If the current comment is a reply to another comment,ParentThe field will contain the complete data of its parent comment. You can check it in the template loopitem.ParentIf it exists, then it can be nested or referenced as<blockquote>The way to display the information of the superior comment in a list format, thus creating a direct dialogue thread effect. When the comment is submitted, the form containsparent_idfield is the basis for the reply function.

3. How to adjust the display quantity or sorting of the comment list?

You can use it tocommentListlabel'slimitandorderParameters can be used to flexibly adjust the display quantity and sorting method of comments. For example,limit="15"15 comments will be displayed each time, andorder="id desc"Comments will be sorted in reverse order by comment ID, which usually means that the most recently posted comments will be displayed at the top.If you need a more complex sorting, such as sorting by likes, you may need to refer to more documents or carry out secondary development.

Related articles

How to implement the labeling display of document Tag list label `tagList`, detail label `tagDetail`, and document list label `tagDataList`?

In website operation, efficient content management and flexible content display are the key to improving user experience and search engine performance.AnQiCMS (AnQiCMS) is well-versed in this, providing powerful tag features to help us easily implement the labeling and display management of content.By skillfully utilizing `tagList`, `tagDetail`, and `tagDataList` as these core tags, we can give wings to the website content, making information organization more scientific, user search more convenient, and also lay a solid foundation for SEO optimization.Core

2025-11-07

How to implement custom attribute display and filtering for document parameter tag `archiveParams` and filter tag `archiveFilters`?

In AnQi CMS, displaying and filtering custom attributes of content is the core of implementing flexible and personalized website functions.By using the `archiveParams` and `archiveFilters` template tags, we can easily display custom content fields on the frontend and provide users with powerful functionality for filtering content based on these fields, thus greatly enhancing the website's user experience and content discoverability.### `archiveParams` Tag: Flexible Display of Custom Properties In AnQi CMS

2025-11-07

How to implement navigation display between content for previous/next document tags `prevArchive`/`nextArchive`?

In website operation, providing readers with a smooth reading experience is the key to enhancing user satisfaction and website value.After a user finishes reading an exciting article or product introduction, if they can conveniently see related content such as 'Previous' or 'Next', it will undoubtedly greatly increase their time spent on the website, forming a more natural browsing path, which is very beneficial for SEO optimization and content dissemination.AnQi CMS, as a powerful content management system, fully understands this need

2025-11-07

How to retrieve and display the full content of a single document using the `archiveDetail` detail tag?

In AnQi CMS, displaying the full content of a single document is the foundation of website operation.Whether you are publishing a news article, a product detail, or a service introduction, the core lies in how to present the data entered in the background efficiently and accurately to the user.This is where the `archiveDetail` tag and its related mechanism come into play.

2025-11-07

How to dynamically generate and display the user's guestbook form with the label `guestbook`?

In website operation, visitor comments and interaction are important for building trust, obtaining feedback, and promoting business development.AnQiCMS (AnQiCMS) understands this need and provides a flexible and powerful message form feature, allowing you to easily generate and display user message forms on your website.This is mainly achieved through its built-in `guestbook` template tag, which not only allows you to customize form fields but also ensures the safety and smooth submission of the form.### Understand `guestbook`

2025-11-07

How to display the link list of cooperative website links with the tag `linkList`?

In website operation, friendship links (also known as cooperative website links) play an important role.They not only bring additional traffic to the website, but also help to improve search engine optimization (SEO) performance, enhance the authority and user trust of the website.In Anqi CMS, managing and displaying these links becomes very convenient, mainly due to its powerful template tag system, especially the `linkList` tag.### Flexibly display cooperative websites: `linkList` tag usage and basic principles `linkList`

2025-11-07

How does the pagination tag `pagination` provide navigation and display control for long content lists?

In website operation, when our content list (whether it is articles, products, or other information) accumulates to a certain amount, displaying all content on a single page not only significantly affects the page loading speed but may also make visitors feel overloaded with information, making it difficult for them to find the content they are really interested in.At this point, a reasonable pagination mechanism is particularly important. AnQiCMS provides a powerful and flexible `pagination` tag, which helps us provide clear navigation and display control for long content lists, thereby greatly optimizing user experience and website performance.Core Function

2025-11-07

How `if` logical judgment tags and `for` loop iteration tags control the conditional display and repeated display of content?

In the daily operation of Anqi CMS, we often need to decide which content should be displayed according to different business logic, as well as how to efficiently repeat the display of a large amount of similar content.At this time, the `if` logical judgment tag and the `for` loop traversal tag have become indispensable tools in template design.They allow us to flexibly control the conditional display and repetition of content, greatly enhancing the dynamicity and maintainability of the website.### The conditional display tool - `if` logical judgment tag The `if` tag is the basis for conditional content display in Anqi CMS templates

2025-11-07