How to display the comment list of articles in AnQiCMS template and support pagination?

Calendar 👁️ 62

Display article comment list and pagination elegantly in AnQiCMS template

Article comments are an important part of website interaction, as they not only enhance user engagement but also bring richer discussions and value to the website content.For operators, how to clearly and efficiently display these comments on the page and support pagination is the key to improving user experience.AnQiCMS provides a set of intuitive and powerful template tags, allowing you to easily achieve this goal.

Understand the basic of AnQiCMS template

AnQiCMS uses a template engine syntax similar to Django, which makes template development flexible and easy to learn. In the template file, you will see two main tag forms: double braces{{变量}}Used to output variable content, while single curly braces and percentage signs{% 标签 %}Used to control logic (such as loops, conditional judgments) or to call specific functions. Template files are usually in.htmlwith suffix, and stored uniformly in/templatedirectory.

To implement displaying a comment list and supporting pagination on the article detail page, we mainly use two core tags:commentListused to retrieve comment data, as well aspaginationused to generate pagination navigation.

Get the article comment list:commentListTag

commentListThe tag is a tool specifically used in AnQiCMS to retrieve article comment data. It can help you easily extract comments under a certain article.

When using this tag, there are several key parameters to pay attention to:

  • archiveIdThis is the most important parameter, it tells the system which article's comments you want to get. Usually, the current article's ID will be automatically provided as such a variable.archive.Idsuch a variable.
  • typeThis parameter determines the type of list you want to retrieve. If set tolist, it will simply return the specified number of comments; if set topageIt will enable pagination for the comment list for subsequent cooperationpaginationlabel usage
  • limit: Used to control how many comments are displayed per page. For example,limit="10"which means 10 comments are displayed per page.
  • order: You can specify the sorting method of comments, such as descending order by ID (id desc) or ascending order (id asc).

When you go throughcommentListThe tag retrieves the comment data and returns an array of comment objects. You can iterate over this array and access the properties of each comment object, such as the comment ID (Id)、Username (UserName)、Comment content (Content)、Likes (VoteCount), Creation time (CreatedTime) etc. It is worth mentioning that the comment content may also contain replies (i.e.')ParentAn object, as well as the review status (Status) can be flexibly displayed in the template.

To implement the comment pagination feature:paginationTag

OncecommentListlabel'stypethe parameter topage, the comment data has the ability to be paginated. At this time,paginationthe tag can fully show its skills, automatically generating a complete set of pagination navigation for you.

paginationCommon parameters for tags areshowIt specifies the maximum number of page number buttons to be displayed in the pagination navigation, for exampleshow="5"It will display up to 5 page numbers around the current page.

paginationThe label will provide a total number of records (TotalItems), Total number of pages (TotalPages)、current page (CurrentPage) Home page (FirstPage) End page (LastPage) Previous page (PrevPage) Next page (NextPage) And the middle page number array (PagesAn object with this information. You can use a loop toPagesarray to build page number buttons, and useIsCurrentthe attribute to judge the current page, so as to

perform operations in the template

We usually integratearchive/detail.htmlcomment features into such article detail templates.

First, make sure you can get the ID of the current article. This is usually done through{{archive.Id}}Directly obtain, or use{% archiveDetail archiveInfo with name="Id" %}To obtain more explicitly.

Next, we can build the comment list and pagination.

Display the comment list

The following code snippet demonstrates how to display the comment list on the article detail page template and handle the review status and reply relationship:

”`twig {# Get the current article ID to associate comments #} {% archiveDetail currentArchiveId with name=“Id” %}

Reader's Comments

{% commentList comments with archiveId=currentArchiveId type="page" limit="10" order="id desc" %} {% for item in comments %}
{% if item.Status != 1 %}Under review:{{ item.UserName|truncatechars:6 }} {% else %} {{ item.UserName }} {% endif %}{% if item.Parent %}Reply {% if item.Parent.Status != 1 %}Under review:{{ item.Parent.UserName|truncatechars:6 }} {% else %} {{ item.Parent.UserName }} {% endif %}{% endif %}{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}
{% if item.Parent %}

{% if item.Parent.Status != 1 % The content is under review: {{ item.Parent.Content|truncatechars:100 }} {% else %} {{ item.Parent.Content|truncatechars:100 }} {% endif %}

{% endif %}

{% if item.Status != 1 %} The content is under review: {{ item.Content|truncatechars:100 }} {% else %} {{ item.Content|safe }} {% endif %}

{% empty %}

No comments yet, come and share your views!

{% endfor %} {% endcommentList %}
{# 评论分页代码 #}
<div class="comment-pagination">
    {% pagination pages with show="5" %}
        <ul>
            <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
            </li>
            {% 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 %}
            <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                <a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
            </li>
        </ul>
    {% endpagination %}
</div>

{# 评论提交表单 #}
<div class="comment-form-section">
    <h3>发表评论</h3>
    <form method="post" action="/comment/publish" class="comment-submit-form">
        <input type="hidden" name="return" value="html">
        <input type="hidden" name="archive

Related articles

How to implement the parameter filtering function of the article list in AnQiCMS (such as filtering by custom properties)?

As the content of the website becomes richer, users often hope to find the information they are interested in more accurately, rather than searching for a needle in a haystack of disordered content.For operators, providing flexible article list filtering functions can not only significantly improve user experience but also effectively help users discover more related content, thereby increasing the time spent on the website and interaction.AnQiCMS fully understands this need, through its highly flexible content model and powerful template tag system, making it extremely simple and intuitive to implement the parameter filtering function for the article list.Even if it is a custom attribute

2025-11-07

How to display Markdown formatted article content in AnQiCMS template and render it correctly to HTML?

In a content management system, Markdown has become the preferred writing format for many content creators, it is concise, efficient, and easy to convert to structured HTML.For AnQiCMS users, using Markdown to write articles can not only improve writing efficiency but also better organize content structure.Luckyly, AnQiCMS deeply supports Markdown formatted article content and provides a perfect mechanism to ensure that they are correctly rendered into beautiful HTML pages on the website front-end.### Start

2025-11-07

How does AnQiCMS template reference other template files (such as `header.html`, `footer.html`) to achieve code reuse?

In website construction and maintenance, how to efficiently manage code and avoid redundant labor is the key to improving development efficiency and ensuring website consistency.For users who build websites using AnQiCMS, its flexible template engine provides a powerful code reuse mechanism, allowing us to easily refer to other template files, such as the common header (header) and footer (footer), thereby achieving modular development.The template design of AnQiCMS borrows the syntax features of the Django template engine

2025-11-07

How to define and use temporary variables in AnQiCMS templates to simplify complex data processing?

In AnQiCMS template development, we often encounter situations where we need to process or reuse complex data.Writing complex logic or data paths repeatedly in templates not only makes the code long and hard to read, but also affects maintenance efficiency.At this time, skillfully using temporary variables can make template code clearer and more concise, as well as more flexible in data processing.AnQiCMS's template engine provides a powerful and flexible variable definition mechanism that can help us effectively manage and process page data.

2025-11-07

How to integrate the message form into the AnQiCMS template and dynamically display the custom form fields configured in the backend?

In today's digital world, websites are not just platforms for displaying information, but also important bridges for interaction and communication with users.A well-designed, feature-complete feedback form that can greatly enhance user experience, help websites collect feedback, and gain business opportunities.AnQiCMS (AnQiCMS) is well-versed in this, providing powerful message form integration capabilities. Particularly impressive is that it allows us to flexibly configure custom form fields through the backend and dynamically present these fields in the frontend template, thereby meeting various personalized business needs

2025-11-07

How to get and display the current year in AnQiCMS template?

When building and maintaining websites, we often need to display some dynamic information on the page, such as the current year.This is very useful for copyright statements, annual reports, or any scenario that requires real-time year information.AnQiCMS with its concise and efficient template system makes it easy to obtain and display the current year.AnQiCMS's template system borrows the syntax of the Django template engine, which means it provides intuitive tags and variables to manipulate content.

2025-11-07

How to implement multilingual site switch link display in AnQiCMS template and set hreflang?

Building multilingual websites in AnQiCMS and providing convenient language switching functions and correct SEO settings is a key step in expanding the international market and enhancing user experience.As a modern content management system developed based on the Go language, AnQiCMS provides strong and flexible support in this aspect, allowing content operators to easily manage global content publishing needs.

2025-11-07

How to dynamically fetch and display the cover thumbnail of an article or category in the AnQiCMS template?

In website operations, carefully designed thumbnails are crucial for attracting user clicks, enhancing page aesthetics, and optimizing search engine (SEO) performance.AnQiCMS as a powerful content management system fully considers this point, providing a flexible and convenient way to manage and call the cover thumbnails of articles, categories, and other content. ### AnQiCMS Thumbnail Mechanism Overview The AnQiCMS thumbnail mechanism is very intelligent and user-friendly.When publishing an article, the system allows you to manually upload a thumbnail.

2025-11-07