WordPress nested reply (comparison of advantages and disadvantages)

Time:2020-3-23

1. It can improve the user experience, mobilize the enthusiasm of visitors to reply, increase the number of comments, and make the blog become as active as the community
2. The blog’s reply email notification function is getting more and more attention, because it can retain some tourists for you. In addition, the reviewers don’t need to come back frequently to check whether they have been replied or not after they have made comments, which can improve the interactivity to a certain extent. Nested replies can respond to comments pertinently, and the reviewers can know their answers as long as they receive emails
Other people don’t use nested replies. I’m one of them. Why? Listen to me. Everything has its advantages and disadvantages. Nested replies also have some disadvantages:
1. Nested reply is a display structure that depends on the program. That is to say, as long as you use it once, you must use it later. Otherwise, the order of comments will be disordered. Suppose there are three people, a, B and C, who have commented once. The operation is as follows:
A added a comment
B also added a comment
C replied to a’s comment
If the topic supports nested replies, you will get the following display structure:
  
However, if the topic does not support nesting, it will display as follows:
 
That is to say, the page structure will become extremely chaotic. You have to let the current theme support nested replies or use plug-ins to support them. This is the dependence on the program. Unless you are proficient in its production principle, it will limit your choice of themes and plug-ins

2. The targeted reply function of nested reply (reply to a comment) is its advantage as well as its disadvantage. If 100 people have commented in one of your articles and you are used to reply to most of the comments, do you need to reply almost 100 times? If so, @ reply is more suitable for you than nested reply

3. Nested reply depends on the browser’s support for JavaScript

I don’t use nested replies for the first two reasons. I’m not sure I’ll use nested replies all the time in the future. In my respondents, several people often ask the same question. Using @ reply is a compromise choice. I can answer the comments of netizens in one reply, and I don’t need to answer the same questions many times. In addition, Through some plug-ins, I can also reply to email notifications, only email content is slightly complex

How to integrate nested reply into a topic?

There are two ways to implement nested reply in the theme, including the default method provided by WordPress and the custom callback method. Next, I will explain how to implement nested structure. Please study the CSS part by yourself

Default method:
WordPress provides the basic nesting style, which is used by the default theme
Advantages: easy to use, reduce the amount of code
Disadvantages: the code structure is not good, it can not be suitable for all topics
The implementation steps are as follows:

1. In the header.php<?php wp_head(); ?>Add the following code ahead

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> <SPAN style=”COLOR: #b1b100″>if</SPAN><SPAN style=”COLOR: #009900″>(</SPAN>is_singular<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #009900″>)</SPAN> wp_enqueue_script<SPAN style=”COLOR: #009900″>(</SPAN> <SPAN style=”COLOR: #0000ff”>’comment-reply'</SPAN> <SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>

Its function is to load the JavaScript code needed for nested replies
2. Add the following code at the top of the comments.php file

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN>
<SPAN style=”COLOR: #b1b100″>if</SPAN> <SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #339933″>!</SPAN><SPAN style=”COLOR: #990000″>empty</SPAN><SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #000088″>$_SERVER</SPAN><SPAN style=”COLOR: #009900″>[</SPAN><SPAN style=”COLOR: #0000ff”>’SCRIPT_FILENAME'</SPAN><SPAN style=”COLOR: #009900″>]</SPAN><SPAN style=”COLOR: #009900″>)</SPAN> <SPAN style=”COLOR: #339933″>&&</SPAN> <SPAN style=”COLOR: #0000ff”>’comments.php'</SPAN> <SPAN style=”COLOR: #339933″>==</SPAN> <SPAN style=”COLOR: #990000″>basename</SPAN><SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #000088″>$_SERVER</SPAN><SPAN style=”COLOR: #009900″>[</SPAN><SPAN style=”COLOR: #0000ff”>’SCRIPT_FILENAME'</SPAN><SPAN style=”COLOR: #009900″>]</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #009900″>)</SPAN> <SPAN style=”COLOR: #009900″>{</SPAN>
<SPAN style=”COLOR: #990000″>die</SPAN> <SPAN style=”COLOR: #009900″>(</SPAN>__<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #0000ff”>’Please do not load this page directly. Thanks!'</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN>
<SPAN style=”COLOR: #009900″>}</SPAN>
<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>

3. Add the following code to comment list element of comments.php file to call all related comments

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> wp_list_comments<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>

4. Add the following code inside the id = “commentform” element of comments.php

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> comment_id_fields<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>

And the form’s appropriate cancel reply button, code as follows

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> cancel_comment_reply_link<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>

5. All the codes calling the comment part are
1

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> comments_template<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>
<?php comments_template(); ?>

Change to the following code
1

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> comments_template<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #0000ff”>”</SPAN><SPAN style=”COLOR: #339933″>,</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #009900″>true</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>
<?php comments_template(”, true); ?>

Callback method:
On the basis of basic nesting, the callback method is defined to redefine the content and layout of comments
Advantages: flexible
Disadvantage: add a lot of code
As for the custom nested reply, I misreported a bug in the previous article “update to WordPress 2.7 official edition”. Here, I apologize to all readers who have read this article
1. On the basis of the default method, add a callback function to replace the default comment layout of WordPress. I added a method named custom_comments in function.php. Please note that please don’t add the closing < / Li > tag, and I will explain why it can’t be added in the following articles
2. In comments.php
1

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> wp_list_comments<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>
<?php wp_list_comments(); ?>

Change to the following code to call the custom_comments method
1

Copy code

The code is as follows:

<SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″><?php</SPAN> wp_list_comments<SPAN style=”COLOR: #009900″>(</SPAN><SPAN style=”COLOR: #0000ff”>’callback=custom_comments'</SPAN><SPAN style=”COLOR: #009900″>)</SPAN><SPAN style=”COLOR: #339933″>;</SPAN> <SPAN style=”FONT-WEIGHT: bold; COLOR: #000000″>?></SPAN>
<?php wp_list_comments(‘callback=custom_comments’); ?>

Detailed code can refer to my production of blocks theme
What topic is suitable for adding nested replies?
It’s troublesome to add nested replies to a topic. It’s very frustrating and will disrupt the whole topic structure. Up to now, I still doubt whether the official should support nested replies natively. But since it supports nested replies, it’s a good idea to try. Is that all topics are suitable for adding nested replies? I don’t think so
It’s obviously not suitable for topics with many pictures or complex comment page structure. That’s why I haven’t added nested reply function in iNove. But for topics that don’t depend on pictures, such as blocks, it’s very suitable for adding
In addition, we need to judge whether nested reply is supported and how many layers of reply are supported according to your requirements. The deepest level is 10, but we can only support the second or third layer to reduce the development cost
Epilogue
I don’t know why I’ve been asked many times about nested replies. Because nested replies are complex to implement and difficult to maintain, and for other reasons, many topics don’t support nested replies, but many people like it very much. I think I can share my understanding with you
Next, I will talk about “how nested replies work” and “how to implement nested replies on the premise of compatibility with multiple WordPress versions”. If you have better suggestions or any comments, please leave a message here
WP Trick Comments, Talk, Theme, Tutorial, WordPress
Statement: the site follows the signing – non-commercial use – sharing agreement 3.0 in the same way. Please indicate the transfer from NeoEase
Related Posts
In wordpress blog, the trailer (33) usually plays some clips from the next episode as the trailer at the end of a TV program. This can make the audience more interested
The principle of WordPress nested reply (30) in the previous article (WordPress nested reply), I have introduced the advantages and disadvantages of nested reply, production methods, etc
WordPress multi-level navigation menu (57) difficulty: ★★★★ multi level navigation menu, which means that there are multiple levels of menus, nested layer by layer, when the mouse moves to a menu
Use Image Title in iNove (57) The most frequently asked question about iNove …
Change Header Color of iNove (67) Now I’ll show you how to change the header colo…