How to display the user submitted comment list on a website and support pagination?

Calendar 👁️ 70

Displaying user comments on a website and supporting pagination is an important element in enhancing content interactivity and user experience.AnQiCMS provides flexible template tags and data management functions, allowing us to easily meet this requirement.Next, let's look at how to operate step by step.

Comment feature: make the content more vibrant

We all know that user comments are a reflection of the vitality of website content.They can not only bring real user feedback to the website but also effectively increase the freshness of the page and the attention of search engines.In AnQiCMS, displaying these comments and providing a good browsing experience (such as pagination) is a very direct and practical operation.

In general, we would display comments related to the content at the bottom of an article or product detail page.The AnQiCMS template system is very flexible, we can easily render comment data to the page by using the specific tags it provides.

Core tags for displaying the comment list:commentList

We need to use AnQiCMS'scommentListtag. This tag is specifically designed to retrieve and display comment data.

First, you need to determine where the comment should be displayed below an article or content. On the document details page, we are usually able to pass througharchiveDetailThe tag retrieves the ID of the current document. This ID will be the key parameter for fetching comments.

commentListThe basic usage of the tag is roughly like this:

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

There are several important parameters in this.

  • commentsThis is the variable name you define for the comment list data, you can name it as needed. In{% endcommentList %}we will pass throughcommentsthis variable to iterate over each comment.
  • archiveId=archive.IdThis is to tell the system which document's comments to retrieve.archive.IdIt is through other tags (such asarchiveDetail) The document ID has been obtained. If you want to specify comments for other documents, you can also directly fill in the specific ID, for examplearchiveId="1".
  • type="page"This parameter is very critical. It indicates that we want to display comments in a paginated form rather than simply listing all comments. This lays the foundation for adding pagination navigation later.
  • limit="10"This defines how many comments are displayed per page. You can adjust this number based on the design of the website and user habits, for examplelimit="5"orlimit="20".

In{% commentList %}and{% endcommentList %}between, we can useforto loop throughcommentsEach comment in the variable indicated:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {% for item in comments %}
        <div class="comment-item">
            <div class="comment-meta">
                {# 判断评论状态:AnQiCMS 提供了评论审核功能,status=1 表示审核通过 #}
                {% if item.Status != 1 %}
                    <span>审核中:{{ item.UserName|truncatechars:6 }}</span>
                {% else %}
                    <span>{{ item.UserName }}</span>
                {% endif %}

                {# 如果是回复评论,可以显示被回复的用户名 #}
                {% if item.Parent %}
                    <span>回复</span>
                    <span>
                        {% if item.Parent.Status != 1 %}
                        审核中:{{ item.Parent.UserName|truncatechars:6 }}
                        {% else %}
                        {{ item.Parent.UserName }}
                        {% endif %}
                    </span>
                {% endif %}

                <span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</span>
            </div>
            <div class="comment-content">
                {% if item.Parent %}
                <blockquote class="reply-quote">
                    {% if item.Parent.Status != 1 %}
                    该内容正在审核中:{{item.Parent.Content|truncatechars:9}}
                    {% else %}
                    {{item.Parent.Content|truncatechars:100}}
                    {% endif %}
                </blockquote>
                {% endif %}

                {% if item.Status != 1 %}
                    <p class="pending-review">该内容正在审核中:{{ item.Content|truncatechars:9 }}</p>
                {% else %}
                    <p>{{ item.Content }}</p>
                {% endif %}
            </div>
            <div class="comment-actions">
                <a href="javascript:;" class="like-btn" data-comment-id="{{ item.Id }}">赞({{ item.VoteCount }})</a>
                <a href="javascript:;" class="reply-btn" data-comment-id="{{ item.Id }}" data-user-name="{{ item.UserName }}">回复</a>
            </div>
        </div>
    {% empty %}
        <p>目前还没有评论,快来发表你的看法吧!</p>
    {% endfor %}
{% endcommentList %}

We utilized in the above code:itemSeveral commonly used fields of the variable:

  • item.UserName: Nickname of the comment user.
  • item.Content:The specific content of the comment. Here we used:|safeFilter to ensure that the HTML tags in the comment content can be parsed correctly (if your comment editor supports rich text).
  • item.CreatedTime: The timestamp of the comment published bystampToDateLabel it to format it as a readable date and time.
  • item.Status: The review status of the comment, usually1Indicates that the review has passed. We can provide a prompt based on this status when displaying.
  • item.VoteCount: Number of likes on the comment.
  • item.ParentIf this comment is a reply to another comment,item.Parentit will contain the object data of the parent comment, which is very useful for implementing nested reply comments in comment levels.

Add pagination navigation:paginationTag

SincecommentListuptype="page"Then we can add pagination navigation. AnQiCMS providespaginationtags to help us generate standard pagination links.

paginationtags usually followcommentListafter the tag:

<div class="pagination-nav">
    {% pagination pages with show="5" %}
        <ul>
            {# 显示首页链接 #}
            <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
            </li>

            {# 显示上一页链接 #}
            {% if pages.PrevPage %}
                <li><a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a></li>
            {% endif %}

            {# 循环显示中间的页码链接 #}
            {% for pageItem in pages.Pages %}
                <li class="{% if pageItem.IsCurrent %}active{% endif %}">
                    <a href="{{ pageItem.Link }}">{{ pageItem.Name }}</a>
                </li>
            {% endfor %}

            {# 显示下一页链接 #}
            {% if pages.NextPage %}
                <li><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>
            {% endif %}

            {# 显示末页链接 #}
            <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
            </li>
        </ul>
        <p>总数:{{pages.TotalItems}}条,总共:{{pages.TotalPages}}页,当前第{{pages.CurrentPage}}页</p>
    {% endpagination %}
</div>

HerepagesThe variable contains all information related to pagination:

  • pages.TotalItems: Total number of comments.
  • pages.TotalPages: Total number of pages.
  • pages.CurrentPage: Current page number.
  • pages.FirstPage.Linkandpages.FirstPage.Name: Link and display name of the homepage.
  • pages.PrevPage.Linkandpages.PrevPage.Name: Link and display name of the previous page.
  • pages.NextPage.Linkandpages.NextPage.Name: Link and display name of the next page.
  • pages.LastPage.Linkandpages.LastPage.Name: The link and display name on the last page.
  • pages.Pages: An array containing all the middle page number information, we can go throughforloop.
  • pageItem.IsCurrent: Used to determine if the current page number is active, making it convenient to add CSS styles.

show="5"The parameter controls the maximum number of page buttons displayed in the pagination navigation, which can prevent too many page numbers from being displayed

Related articles

How to manage and display image resources, and categorize them in AnQiCMS?

## Secure CMS: The Art of Fine Management and Diversified Display of Image Resources In a content management system, images act as the soul of visual content, and the efficiency of their management and display directly affects the overall quality and user experience of the website.AnQi CMS understands this and provides users with a comprehensive and flexible image resource management solution, from upload and storage to intelligent processing, and to flexible display in various scenarios, striving to achieve the ultimate.### Centralized management of image resources

2025-11-08

How to display the website logo, filing number, and copyright information on the frontend page?

The website's logo, filing number, and copyright information are the three indispensable elements that constitute a professional and trustworthy online image.They not only help with brand recognition and promotion, but are also an important embodiment of compliance with laws and regulations and enhancing the credibility of the website.As a system specially designed for small and medium-sized enterprises and content operation teams, AnQiCMS (AnQiCMS) fully understands the importance of these details and provides an extremely convenient way to manage and display them.

2025-11-08

How to configure and display a canonical URL to optimize search engine crawling?

It is crucial to ensure that search engines efficiently and accurately crawl and understand our content in website operation.Among them, the canonical URL is an indispensable SEO strategy.It can help us solve the problem of duplicate content, concentrate the page weight, and thus optimize the website's performance in search engines.AnQiCMS as a SEO-friendly and powerful content management system naturally also provides comprehensive specification link configuration options, allowing users to easily manage this important function.What is the canonical link

2025-11-08

How to set and display the SEO title, keywords, and description (TDK) of a website in AnQiCMS?

When building a website, Search Engine Optimization (SEO) is the key to ensuring that content is discovered by search engines and attracts potential visitors.And the SEO title (Title), keywords (Keywords), and description (Description), abbreviated as TDK, are one of the most basic and most important elements in website optimization.They directly affect the display and click-through rate of websites in search results.

2025-11-08

How to ensure that AnQiCMS multi-site content is independent and displayed correctly?

When operating multiple websites, we often face a core challenge: how to ensure that each site's content is independently operated and accurately displayed without confusion or misplacement.AnQiCMS (AnQiCMS) is a system designed for multi-site management and provides a well-considered solution in this regard, allowing us to comfortably expand different brands or business branches.**The foundation of building an independent site: from deployment to backend management** When we decide to build multiple sites with Anqi CMS, we start laying the foundation for content independence from the deployment phase.

2025-11-08

How to use a flexible content model to customize the front-end content display structure?

The Anqi CMS provides a very powerful core feature in content management, that is, its 'flexible content model'.This is not just about enabling us to publish traditional articles and product information, but more importantly, it gives us the ability to customize any content structure and display it on the website front-end in the way we want. ### Understanding the Core Value of Flexible Content Models In traditional CMS systems, we are often limited by predefined content types, such as being able to publish only "articles" and "products", which seems inadequate when facing diverse business needs. For example

2025-11-08

How to implement content switching and display on the page for AnQiCMS multilingual support?

In today's globalized internet environment, multilingual support for websites is no longer an optional feature, but a key factor for businesses to expand into international markets and improve user experience.For website operators who want to reach different language audiences, a CMS system that can flexibly manage and display multilingual content is particularly important.AnQiCMS (AnQiCMS) with its powerful functions, provides us with an efficient and convenient multi-language content switching and display solution.

2025-11-08

How can 301 redirects and static redirection optimize website URLs and ensure normal access and display of pages?

Optimize the website URL structure to ensure stable content presentation: The Practical Guide to Static and 301 Redirects of Anqi CMS In today's digital world, a website's URL (Uniform Resource Locator) is not just the address of a page, but also an important part of the website's content and brand image.A clear and meaningful URL structure not only allows visitors to easily understand the content of the page, but is also an important factor for search engines to judge page relevance and optimize rankings.SafeCMS deeply understands this, providing us with powerful static and 301 redirection functions

2025-11-08