Get Separate Count For Comments Trackbacks And Pingbacks In WordPress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function commentCount($type = 'comments'){
  2.  
  3. if($type == 'comments'):
  4.  
  5. $typeSql = 'comment_type = ""';
  6. $oneText = 'One comment';
  7. $moreText = '% comments';
  8. $noneText = 'No Comments';
  9.  
  10. elseif($type == 'pings'):
  11.  
  12. $typeSql = 'comment_type != ""';
  13. $oneText = 'One pingback/trackback';
  14. $moreText = '% pingbacks/trackbacks';
  15. $noneText = 'No pinbacks/trackbacks';
  16.  
  17. elseif($type == 'trackbacks'):
  18.  
  19. $typeSql = 'comment_type = "trackback"';
  20. $oneText = 'One trackback';
  21. $moreText = '% trackbacks';
  22. $noneText = 'No trackbacks';
  23.  
  24. elseif($type == 'pingbacks'):
  25.  
  26. $typeSql = 'comment_type = "pingback"';
  27. $oneText = 'One pingback';
  28. $moreText = '% pingbacks';
  29. $noneText = 'No pingbacks';
  30.  
  31. endif;
  32.  
  33. global $wpdb;
  34.  
  35. $result = $wpdb->get_var('
  36. SELECT
  37. COUNT(comment_ID)
  38. FROM
  39. '.$wpdb->comments.'
  40. WHERE
  41. '.$typeSql.' AND
  42. comment_approved="1" AND
  43. comment_post_ID= '.get_the_ID()
  44. );
  45.  
  46. if($result == 0):
  47.  
  48. echo str_replace('%', $result, $noneText);
  49.  
  50. elseif($result == 1):
  51.  
  52. echo str_replace('%', $result, $oneText);
  53.  
  54. elseif($result > 1):
  55.  
  56. echo str_replace('%', $result, $moreText);
  57.  
  58. endif;
  59.  
  60. }

URL: http://wpcanyon.com/tipsandtricks/get-separate-count-for-comments-trackbacks-and-pingbacks-in-wordpress/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.