As an experienced website operations expert, I am well aware of the importance of the comment function for website activity and user interaction.Among many content management systems, AnQiCMS has won the favor of many operators with its efficient and flexible features.TodayHow can we elegantly display the information of these commenters in the template?

AnQiCMS comment function analysis: Deep Guide to Anonymous Submission and Template Display

AnQiCMS as an enterprise-level content management system based on the Go programming language, is dedicated to providing efficient and customizable content solutions.Its powerful feature set, from multi-site management to advanced SEO tools, provides a solid foundation for content operations.In terms of user interaction, the comment feature is naturally an indispensable part.How does AnQiCMS handle user submitted comments, especially the submission and display of anonymous comments?

Does AnQiCMS support anonymous user comment submission?

In the AnQiCMS comment mechanism, we can find the answer from the structure of its comment form. According to the documentation on the submission of the comment form (tag-/anqiapi-other/158.html),the user needs to provide several key fields when submitting a comment:archive_id(the corresponding document ID),user_name(the username of the commentor) andcontent(the content of the comment). Among which,user_nameThe field is explicitly marked as 'required'.

This means that the AnQiCMS systemdoes not provide a native 'anonymous' comment submission feature. The user must enter a username to successfully submit a comment.However, this does not mean that users cannot implement 'anonymous' comments.This 'anonymous' tends to be a pseudo-anonymous state.Users can choose to fill in a generic name that does not reveal their real identity, such as 'tourist', 'anonymous user', '路人甲', and so on.The system does not require users to register or log in to post comments; it only requires commenters to attach a name to their statements.This design balances the convenience of users submitting comments and the traceability of content.

Therefore, if your operational strategy hopes that users can comment without providing any name, the default comment function of AnQiCMS may not be able to meet this, which may require secondary development or specific logic processing in the front-end template, such as automatically filling in a default value of 'Anonymous User' when the user does not input. But under the default settings,user_nameIt is mandatory to fill in.

How does the template handle the display of the reviewer?

Once the comment is submitted successfully, whether it is a registered user or a 'pseudo-anonymous' user, AnQiCMS will provide the corresponding commenter information during template rendering. This is mainly achieved bycommentListTags to implement. This tag will loop through the comment list, each comment item containsitem) contains a wealth of fields, of which the most directly related to the commentor isUserNameandUserId.

  • UserNameThis field will directly display the name entered by the reviewer at the time of comment submission.For 'pseudo-anonymous' users, this will display their input of 'visitors' or 'anonymous users' and similar names.For registered users, the username they registered with will usually be displayed.
  • UserIdThis field can be used to determine whether the commenter is a registered user. IfUserIdis 0 or empty, it usually means that this is a comment submitted by a non-registered user; ifUserIdIf there is a value, it means that the comment comes from a registered user.

Using these two fields, we can flexibly control the display of the commentator in the template, realizing a more user-friendly user interface:

  1. Basic Display: The simplest way is to output directly in the template{{item.UserName}}. Whatever the user enters will be displayed directly.

    <span>{{item.UserName}}</span>
    
  2. Distinguish between registered users and anonymous usersTo provide users with a clearer understanding, we can judge and display different statuses according toUserIdto determine and display different states. For example, ifUserIdIf the value is 0, it will display 'Anonymous User' or 'Visitor' by default, even if they have entered other names.

    {% if item.UserId == 0 %}
        <span>匿名用户</span>
    {% else %}
        <span>{{item.UserName}}</span> {# 此时item.UserName通常是注册用户名 #}
    {% endif %}
    

    You can also add an identifier to the registered username to enhance distinction:

    {% if item.UserId == 0 %}
        <span>匿名用户</span>
    {% else %}
        <span>{{item.UserName}} (注册用户)</span>
    {% endif %}
    
  3. Processing review statusComments list ofStatusField (Status = 1 indicates approved, Status = 0 indicates in review) can also be combined with the reviewer's information to provide a more comprehensive user experience.

    <div>
        <span>
            {% if item.Status != 1 %}
            审核中:{% if item.UserId == 0 %}匿名用户{% else %}{{item.UserName}}{% endif %}
            {% else %}
            {% if item.UserId == 0 %}匿名用户{% else %}{{item.UserName}}{% endif %}
            {% endif %}
        </span>
        {# 其他评论信息,如时间、内容等 #}
    </div>
    

By using the above method, we can refine the control of the reviewer's information in the AnQiCMS template according to actual operational needs, which can meet the freedom of users to express opinions while maintaining the orderliness and friendliness of the website content management.


Frequently Asked Questions (FAQ)

  1. Does AnQiCMS support comment review functionality?Yes, AnQiCMS supports comment review functionality. In the background "Function Management" under "Content Comment Management", operators can view, review, or delete user submitted comments.The comment submitted newly is subject to review before itStatusThe field is usually 0, and based on this, a 'under review' prompt can be displayed in the template.

  2. I hope that AnQiCMS can automatically display 'Visitor' if the user does not enter a name when commenting.Default requirement for AnQiCMS comment submission form.user_nameThis is a required field. If you want to implement the effect of automatically filling in "Visitor" when no name is entered, you need to perform JavaScript logic processing in the front-end template.Check before form submissionuser_nameIf the field is empty, it will be set to 'Visitor' through JavaScript before submitting.This belongs to the custom front-end development category, not the default automatic filling function provided by AnQiCMS backend.

  3. Can I also display other information about the commentator in the comment list? commentListTag provided.itemField exceptUserNameandUserId, also includesIp(User IP),VoteCount(Like count) andCreatedTime(Comment time) and other information. In the template, you can enrich the displayed content of the commentator based on these fields, such as displaying the publication time, or throughUserIdFurther query the avatar information of the registered user (if the system provides a related field for the user's avatar).Please note that it is usually not recommended to directly display the user's IP address due to privacy considerations.