Separate statistics on comments and comments by wordpress

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.