How to configure the `commentList` tag to display comments for a specific article (`archiveId`)?

Calendar 👁️ 59

I am very happy to analyze the comment management and template configuration skills of Anqi CMS for you in depth.In website content operation, comments are an important bridge connecting users to content.AnQiCMS as an efficient content management system naturally also provides powerful comment functions and flexible template tags to help us accurately control the display of comments.

Today, we will focus on a common and core requirement:How to configurecommentListTags to display only specific articles (archiveId) comments?Let's unravel this mystery step by step.

The comment to the content: It is not just interaction, but also value

Before delving into technical details, let's first consider the significance of comments for website operation.User comments not only provide valuable feedback, enhance the interaction of the content, but also bring long-tail keywords for SEO and enrich the page information.Our CMS is deeply proficient in this field, therefore it has taken精细化 management and display of comments into account from the beginning of system design.

Get to knowcommentListTag: The magic wand of comment display

Anqi CMS provides a powerful and flexible template tag system for developers, among whichcommentListIt is the core tool for obtaining and displaying article comments.You can use it in the template file to render a comment list, such as below the article details page or a dedicated comment aggregation page.

You need to wrap this tag with{% commentList ... %}and{% endcommentList %}and specify a variable name for the comment data you get, such ascomments. Its basic structure is usually as follows:

{% commentList comments with ... %}
    {# 循环展示评论数据 #}
    {% for item in comments %}
        {# 评论的HTML结构 #}
    {% endfor %}
{% endcommentList %}

Accurate positioning:archiveIdThe mystery of parameters

Now, let's solve the core problem: how tocommentListonly display comments for specific articles? The answer lies incommentLista key parameter of the tag:archiveId.

archiveIdThe parameter's function is very intuitive, it clearly tells AnQiCMS which specific article's comment data you want to retrieve. When you arecommentListSet in the labelarchiveIdAt that time, the system will match the corresponding comment in the database according to this ID and return it.

As given in the document.commentListThe example of tag usage clearly illustrates this:

{% commentList comments with itemType="archive" itemId="1" type="page" %}...{% endcommentList %}

HereitemId="1"It actually refers toarchiveId="1"This indicates retrieving comments for the article with ID 1.itemType="archive"It further emphasizes that this is a comment for the article type. In practice, if you have already specifiedarchiveId,itemTypeusually can be omitted, the system will automatically identify.

dynamically obtainarchiveId: The practice of the article detail page **

In most cases, you will display the comments of the article on the article detail page.At this moment, the article ID on the current page is dynamic.archiveobject (in the article detail page, the data of the current article will usually be loaded intoarchivethe variable).

You can use it directly.{{ archive.Id }}To get the current article ID and then assign it tocommentListlabel'sarchiveIdthe parameter. This way, no matter which article detail page the user visits,commentListit can intelligently identify and display the corresponding article comments.

For example, in yourarchive/detail.htmlIn a template such as (or other templates used for article details),archiveVariables usually contain all the data of the current article. At this point, you can configure it like thiscommentList:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# ... 评论列表的渲染逻辑 ... #}
{% endcommentList %}

IfarchiveThe variable is unavailable for some reason, or you may need to load comments at specific locations on non-article detail pages (such as displaying comments for a popular article on the homepage), you can also explicitly througharchiveDetailTag to get the ID of a specified article, for example:

{# 假设您要获取ID为5的文章的评论 #}
{% archiveDetail specificArchive with name="Id" id="5" %}
    {% commentList comments with archiveId=specificArchive type="page" limit="10" %}
        {# ... 评论列表的渲染逻辑 ... #}
    {% endcommentList %}
{% endarchiveDetail %}

But on the article detail page, use it directlyarchive.IdIt is usually a more concise and efficient way.

Complete example: Build a fully functional comment section

Here is a template code example that combines obtainingarchiveId, displaying comment lists, comment status judgment, and basic pagination. This code is usually placed in your article detail template (such astemplate/您的模板名/archive/detail.htmlBelow the article content.

"twig {# 假设您正在文章详情页,且当前文章对象为archive` #

{# 显示文章评论总数,通常通过 archive.CommentCount 获取 #}
<h2>文章评论 ({{ archive.CommentCount }})</h2>

{# 配置 commentList 标签,关键在于 archiveId=archive.Id #}
{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {% if comments %}
        <ul class="comment-list">
            {% for item in comments %}
                <li class="comment-item">
                    <

Related articles

In AnQiCMS, how can the `commentList` tag implement pagination for comment data?

As an experienced website operations expert, I am well aware that the comment function in a content management system not only increases user interaction but also brings vitality and richness to the website.AnQiCMS (AnQiCMS) is an efficient content management system developed based on the Go language, which provides strong comment functions while also considering the flexibility of template creation.Today, let's delve into how to elegantly implement pagination of comment data using the `commentList` tag in AnQiCMS.--- ### AnQiCMS in English

2025-11-06

How to use the AnQiCMS `commentList` tag to display comments on the frontend page?

As an experienced website operations expert, I know that an active website cannot do without user interaction, and the comment feature is an important embodiment of user participation.In AnQiCMS (AnQiCMS), integrating and displaying comments is not difficult.Today, let's delve deep into how to use the powerful `commentList` tag of AnQiCMS to elegantly present comment content on your website's frontend page, thereby enhancing user engagement and content vitality.

2025-11-06

How to truncate long category names in the `categoryList` loop and add an ellipsis?

## Enterprise CMS Template Tips: Gracefully truncate long category names and add ellipsis In website operation, the display of category names may seem trivial, but it actually has a significant impact on user experience and page aesthetics.A well-designed website ensures that all its elements can coexist harmoniously, especially the navigation and text in the list.When the category name is too long, it may cause layout confusion, text overflow, and even poor display on different devices, seriously affecting the user's reading experience

2025-11-06

`categoryList` returns the category data whether it includes user group or permission-related setting information?

In the daily operation and template development of AnQi CMS, we often need to obtain site data from different angles, and the category list (`categoryList`) is undoubtedly one of the most commonly used tags.However, regarding whether the `categoryList` returned classification data includes user group or permission-related setting information?This topic, we delve into the design philosophy and functional implementation of AnqiCMS, revealing the logic behind it.

2025-11-06

What sorting methods does the AnQiCMS comment list support (`order` parameter), and how to sort by the latest or the most popular?

As an experienced website operations expert, I am well aware of the importance of user interaction in content management.The comment feature is an important indicator of website activity, and how efficiently and friendly these comments are displayed directly affects user experience and the spread of content.AnQiCMS as a powerful content management system also provides flexible configuration options for comment management.Today, let's delve into the sorting method of AnQiCMS comment list, especially how to display comments based on the latest release or popularity.--- ##

2025-11-06

How to limit the number of comments displayed per page or in total in the `commentList` tag (using the `limit` parameter)?

As an experienced website operations expert, I know that paying attention to details often determines the quality of user experience and page performance.Comments as an important part of website interactivity directly affect users' perception of content through the rationality of their display methods.In a system like AnQiCMS (安企CMS) that is efficient and flexible, how to finely control the number of comments displayed is a topic worth in-depth discussion.Today, let's talk about the妙用 of the `limit` parameter in the `commentList` tag.

2025-11-06

What are the required fields on the AnQiCMS comment submission form to successfully post a comment?

In website operation, user comments are undoubtedly an important way to enhance website interactivity, accumulate community content, and obtain user feedback.For AnQiCMS users, understanding which core fields are required in the comment submission form is crucial, as this not only concerns whether the comment can be successfully published, but also directly affects user experience and the richness of website content.As an experienced website operations expert, today I will delve into the essential fields of the AnQiCMS comment submission form and the logic behind them.

2025-11-06

How to customize the input fields of the AnQiCMS comment submission form to meet specific business requirements?

## AnQi CMS comment submission form field customization: How to meet your unique business needs?Today, with the increasing refinement of digital marketing, every interactive link on the website carries the important mission of collecting user feedback and deepening user relationships.The comment section, as a place for users to directly interact with content, the flexibility of the submitted form directly affects whether we can efficiently obtain the information we need.As an experienced website operation expert, I deeply understand that AnQiCMS (AnQi Content Management System) provides strong support for small and medium-sized enterprises and content operation teams with its efficient and customizable features.

2025-11-06