How to display the user nickname, comment content, and posting time in the AnQiCMS comment list?

Calendar 👁️ 73

In AnQiCMS, the comment feature is an important part to enhance the interactivity of the website.How to clearly and beautifully display the valuable comments left by users on the website, which is the focus of website operators.AnQiCMS provides flexible template tags, allowing us to easily customize the display of the comment list, including user names, comment content, and posting time, etc., core information.

To implement the display of comment lists, we mainly use the template tag system of AnQiCMS. This usually involves editing specific parts of the website template files.

1. Determine the template file for the comment list

Firstly, we need to find the template file responsible for rendering the comment list. According to the template conventions of AnQiCMS, the comment list page is usually located atcomment/list.htmlOf course, if your website uses a custom template structure, you may need to find or create the corresponding display location according to the actual situation in the current article detail page or the specific block referenced by the template file.

2. IntroductioncommentListTag to get comment data

AnQiCMS providedcommentListThe tag is specifically used to obtain the comments of a specified article. When using this tag, we need to clarify the following key parameters:

  • archiveIdThis is the most important item, it specifies which document (article, product, etc.)'s comments to retrieve. Usually, on the article detail page, we canarchive.IdGet the ID of the current article and pass it tocommentList.
  • type: Determines the display style of the comment list. Set to"page"It can achieve pagination, while set to"list"It will only display a specified number of comments without pagination.
  • limit: Controls the number of comments displayed per page or each time. For example,limit="10"It means 10 comments are displayed per page.

Next iscommentListThe basic usage structure of tags:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 在这里循环显示每条评论 #}
{% endcommentList %}

Here, commentsIt is a custom variable name that will contain the collection of comments data obtained, and we will traverse it in the subsequent loop.

3. Traverse comments and display the required information

After obtaining the collection of comment data, we can useforTraverse the tags one by one to display the detailed information of each comment. Inside the loop,itemThe or you can define your own loop variable name will represent the current comment object, and we can access all properties of the comment through it.

Display the user nickname (UserName)

Each comment's user nickname can be obtained throughitem.UserName. Considering that comments may be in review status, we can add a simple judgment to prompt the user:

<span>
    {% if item.Status != 1 %}
    审核中:{{item.UserName|truncatechars:6}} {# 审核中的用户昵称可能截断显示 #}
    {% else %}
    {{item.UserName}}
    {% endif %}
</span>

Display the comment content (Content)

The specific content of the comment passesitem.ContentRetrieve. It should be noted that the comments posted by users may contain HTML tags. In order to ensure that these contents are correctly parsed and not displayed as source code, we need to use|safeFilter. If the comment content is too long, you can also use it in conjunction with|truncatecharsFilter to truncate the display and keep the page neat.

{% if item.Status != 1 %}
    该内容正在审核中:{{item.Content|truncatechars:9|safe}} {# 审核中的评论内容可能截断显示并加提示 #}
{% else %}
    {{item.Content|safe}}
{% endif %}

Display publish time (CreatedTime)

Comment publish time (item.CreatedTime) is a timestamp, we need to use the AnQiCMS providedstampToDatetag to format it so that it can be presented to users in a more readable way.stampToDateThe second parameter is the Go language's time formatting string, you can adjust it as needed. For example,"2006-01-02 15:04"It will be displayed as "Year-Month-Day Hour:Minute".

<span>{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>

Display reply comment (Parent)

AnQiCMS's comment system also supports multi-level replies. If the current comment is a reply to another comment, you can useitem.ParentThe object retrieves information about the parent comment, thus constructing a comment list with more hierarchy.

{% if item.Parent %}
<blockquote>
    {# 显示父级评论的用户名和内容 #}
    <span>回复 {{item.Parent.UserName}}:</span>
    {% if item.Parent.Status != 1 %}
        该内容正在审核中:{{item.Parent.Content|truncatechars:100|safe}}
    {% else %}
        {{item.Parent.Content|truncatechars:100|safe}}
    {% endif %}
</blockquote>
{% endif %}

4. Add pagination feature

If the number of comments is large, the pagination feature will greatly enhance the user experience. IncommentListSet in the labeltype="page"after that, we can cooperatepaginationtags to display the pagination links.

{# 假设上面的 commentList 标签已设置为 type="page" #}
<div>
    {% pagination pages with show="5" %}
        {# 首页 #}
        <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {# 上一页 #}
        {% if pages.PrevPage %}
        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        {% endif %}
        {# 中间多页 #}
        {% for pageItem in pages.Pages %}
        <a class="{% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
        {% endfor %}
        {# 下一页 #}
        {% if pages.NextPage %}
        <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        {% endif %}
        {# 尾页 #}
        <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
    {% endpagination %}
</div>

5. Complete code example

Integrate the above snippet, the following is a basic comment list display code that includes user nickname, comment content, publish time, and pagination features:

"twig {# Assume archive.Id is the ID of the current article, replace it as needed #}

<h3>用户评论</h3>
{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {% for item in comments %}
    <div class="comment-item">
        <div class="comment-meta">
            <span class="user-name">
                {% if item.Status != 1 %}
                    审核中:{{item.UserName|truncatechars:6}}
                {% else %}
                    {{item.UserName}}
                {% endif %}
            </span>
            {% if item.Parent %}
                <span class="reply-to">回复</span>
                <span class="parent-user-name">
                    {% if item.Parent.Status != 1 %}
                        审核中:{{item.Parent.UserName|truncatechars:6}}
                    {% else %}
                        {{item.Parent.UserName}}
                    {% endif %}
                </span>
            {% endif %}
            <span class="publish-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
        </div>
        <div class="comment-content">
            {% if item.Status != 1 %}
                <p class="moderating-tip">该内容正在审核中,稍后可见。</p>
                <p class="comment-text">{{item.Content|truncatechars:100|safe}}</p>
            {% else %}
                {% if item.Parent %}
                    <blockquote class="parent-comment-quote">
                        <p>{{item.Parent.Content|truncatechars:100|safe}}</p>
                    </blockquote>
                {% endif %}
                <p class="comment-

Related articles

How does the AnQiCMS template display or hide specific content based on user group permissions?

In website operation, displaying or hiding specific content based on user identity is a common strategy, which can help us meet various business needs such as member exclusive, paid content, and internal information distribution.AnQiCMS provides flexible user group management features, combined with its powerful template engine, it can easily implement content control based on user group permissions. ### Learn about AnQiCMS user group mechanism AnQiCMS is built with a complete user group management and VIP system.In the background, we can create different user groups

2025-11-09

How to use the `pagination` tag of AnQiCMS to implement pagination navigation on the article list page?

In website content operation, the pagination navigation of the article list page is a key link to improve user experience and optimize search engine crawling efficiency.AnQiCMS as a feature-rich enterprise-level content management system, provides us with a simple and efficient `pagination` tag, making it easy to implement this feature.Next, we will discuss in detail how to use the `pagination` tag to implement page navigation on the article list page of AnQiCMS.

2025-11-09

How to process thumbnails and display images of different sizes in AnQiCMS templates?

Managing website content in AnQiCMS, image processing is undoubtedly a key factor in improving user experience and page loading speed.A website that can intelligently present thumbnails of images in appropriate sizes for different display scenarios can not only greatly improve the page response speed but also make the visual layout more coordinated and beautiful.The AnQi CMS provides a powerful and flexible image thumbnail processing mechanism, which can be easily implemented, whether through unified settings in the background or on-demand calls in the frontend template.### Back-end Content Settings

2025-11-09

How to display the category name and link of the article belonging to the AnQiCMS document detail page?

In AnQiCMS, we often hope that visitors can clearly see the category name of this article when browsing the document details, and can conveniently click on the category link to further explore more content under the same category.This not only optimizes the user experience and makes the website structure more intuitive, but also helps search engines better understand the content hierarchy of the website, improving SEO effects. To implement this feature on the document detail page of AnQiCMS, we need to make some simple modifications to the template file.AnQiCMS uses something similar to Django

2025-11-09

How to format the timestamp into the display format of 'Year-Month-Day Hour:Minute' in AnQiCMS template?

In website content management, the clear display of time information is crucial for user experience.Whether it is the release date of an article or the submission time of comments, a format that conforms to reading habits can make information communication more effective.AnQiCMS provides flexible template functionality, allowing us to easily format timestamps.

2025-11-09

How to display hreflang tags for users of different languages on the AnQiCMS website?

In the operation of multilingual websites, it is crucial to ensure that search engines can accurately understand the language and region targeted by your content, which is essential for improving user experience and search engine optimization (SEO).The `hreflang` tag is the key tool to solve this problem.It tells search engines that your site has content variants for different languages or regions, thus avoiding duplicate content issues and helping search engines to display the most relevant pages to users of different languages.

2025-11-09

How to display the introduction and Banner image of the current category in the AnQiCMS template?

How to make your category page on the website more attractive while clearly conveying information is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) with its flexible template system allows you to easily display the introduction of the current category and personalized Banner images on the category page. We will explore together how to implement this feature in the AnQiCMS template, making your website category page more vivid and professional.### 1. Deeply understand the AnQiCMS template system AnQiCMS

2025-11-09

How to dynamically generate page Title, Keywords and Description using `tdk` tag in AnQiCMS template?

In today's internet environment where content is exploding, Search Engine Optimization (SEO) is crucial for a website's visibility.And the Title (title), Keywords (keywords), and Description (description) on the website page, which we commonly call TDK, are key factors for search engines to understand page content, decide whether to display it to users, and whether users will click.In AnQiCMS, a content management system designed specifically for small and medium-sized enterprises and content operation teams, dynamically generating these TDK information is to enhance the website

2025-11-09