Hello everyone, I haven't seen you for a few days. Have you missed me? There have been nothing to do over the past two days, so I had to continue digging in the comments. Just write it. Don't let the fire break off today .. the effect of this Code implementation is to calculate the primary comments (number of floors) and subcomments (number of replies) respectively. There is no nonsense. Go to the code. effect: Add the following code to functions. phpfunctionseparate_comment
Hello everyone, I haven't seen you for a few days. Have you missed me? There have been nothing to do over the past two days, so I had to continue digging in the comments. Just write it. Don't let the fire break off today .. the effect of this Code implementation is to calculate the primary comments (number of floors) and subcomments (number of replies) respectively. There is no nonsense. Go to the code. effect: Add the following code to functions. php function separate_comment
Hello everyone, I haven't seen you for a few days. Have you missed me?
There have been nothing to do over the past two days, so I had to continue digging in the comments. Just write it. Don't let the fire break off today ..
The effect of this Code implementation is to calculate the primary comments (number of floors) and subcomments (number of replies) respectively. There is no nonsense. Go to the code.
Effect:
Add the following code to functions. php:
function separate_comment_count($id){global $wpdb;$outputn = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE comment_approved = '1' AND comment_post_ID = $id AND comment_parent = '0'";$parents = $wpdb->get_row($outputn);return $parents->count;}
The following code is placed behind the code that originally showed the number of comments,
ID); $ children_count = $ post-> comment_count-$ parents_count; echo ": Heap ". $ parents_count. "FLOOR +"; // if you want to work properly, replace it with echo "main comment :". $ parents_count; echo "yes ". $ children_count. "Building push"; // if you want to work properly, replace it with echo "subcomment :". $ children_count;?>
Q &:
-Can this code be used in other tricks?
-Some comrades use this function when presenting comments. (Or ), These functions are used to convert the number of comments, 0 → grab the sofa, 1 → the bench is still there. however, if only one person comments and receives a reply, because the reply comments are also included in the total comments, the bench is still there, however, the number of comments won't show that the bench is still there... how can this make people prepare to compete for the bench?
So we can separate the comments and subcomments to accurately locate the status of the bench and floor (well, I know I'm bored ), we can judge based on the Code described above. If $ parents_count is 1, the output is: the bench is still there. If it is 2, the output floor is still there, this is more accurate than the native wordpress Comment count.
Original article address: wordpress collects comments and comments separately. Thank you for sharing them.