{"id":623,"date":"2009-01-19T14:20:58","date_gmt":"2009-01-19T13:20:58","guid":{"rendered":"http:\/\/wpengineer.com\/?p=623"},"modified":"2009-12-16T13:46:53","modified_gmt":"2009-12-16T12:46:53","slug":"comment-ping-count","status":"publish","type":"post","link":"https:\/\/wpengineer.com\/623\/comment-ping-count\/","title":{"rendered":"Comment And Ping Count In WordPress 2.7"},"content":{"rendered":"<p>The comment area changed a lot in <strong>WordPress 2.7<\/strong>. A good reason to check your comments.php and make some changes to it. Especially I like to seperate the <strong>comments<\/strong> from <strong>Ping- and Trackbacks<\/strong>. Matt shows in an excellent tutorial how to do it: <a href=\"http:\/\/sivel.net\/2008\/10\/wp-27-comment-separation\/\" title=\"Matts Tutorial\" >Separating Pings from Comments<\/a>. <\/p>\n<p>But I didn&#8217;t like one thing in this tutorial. To show the total count of your comments without Pings\/Trackbacks, he writes following function in functions.php:<br \/>\n<!--more--><\/p>\n<pre lang=\"php\">\r\n<?php\r\nadd_filter('get_comments_number', 'comment_count', 0);\r\nfunction comment_count( $count ) {\r\n\tglobal $id;\r\n\t$comments_by_type = &#038;separate_comments(get_comments('post_id=' . $id));\r\n\treturn count($comments_by_type['comment']);\r\n}\r\n?>\r\n<\/pre>\n<p>This filter will assign globally of course. But in our blog right under the post title we have  the number of comments displayed. If there is no comment but for example 2 Pingbacks, it still shows 0 comments, even though Pingbacks are kind of a comment.<\/p>\n<h3>The Solution<\/h3>\n<pre lang=\"php\">\r\n<?php\r\nif ( ! empty($comments_by_type['comment']) ) :\r\n    $count = count($comments_by_type['comment']);\r\n    ($count !== 1) ? $txt = \"Comments\" : $txt = \"Comment\"; ?>\r\n    <h3 id=\"comments\"><?php echo $count . \" \" . $txt; ?><\/h3>\r\n<\/pre>\n<p>The same for Pings and everything is perfect. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The comment area changed a lot in WordPress 2.7. A good reason to check your comments.php and make some changes to it. Especially I like to seperate the comments from Ping- and Trackbacks. Matt shows in an excellent tutorial how to do it: Separating Pings from Comments. But I didn&#8217;t like one thing in this [&hellip;]<\/p>\n","protected":false},"author":323,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[23,87,89,88,3],"class_list":["post-623","post","type-post","status-publish","format-standard","hentry","category-wordpress-hacks","tag-comments","tag-hacks","tag-ping","tag-trackback","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/comments?post=623"}],"version-history":[{"count":0,"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/posts\/623\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/media?parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/categories?post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpengineer.com\/wp-json\/wp\/v2\/tags?post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}