I'd like my subtitles during my Wordpress blog to count the amount of Facebook comments on my small publish. After placing Facebook's code

<span class="comment-count">
   <fb:comments-count href="<?php echo get_permalink($post->ID); ?>">
   </fb:comments-count> comments

I understand that after I have only 1 comment it prints "1 comments", in plural. What alterations in the code should i do to be able to:

  • print "No comments" when no comments
  • print "1 comment" in singular, when just one comment
  • print "X comments" in plural, when several comment

Sorry if this sounds like a dumb question however i am brand-new to coding (PHP), Wordpress and also the Facebook tools.

While using fb:comments-count tag alone, you cannot. What you ought to do is get the amount of comments right into a PHP variable first after which print the right phrase with respect to the worth of that variable. You are able to retrieve the amount of comments while using PHP SDK, FQL, or even the Graph API. Then, one method to print what you would like:

 $comments = getCommentCountUsingGraphAPI();

 if ($comments == 0) {
    echo "No comments";
 } elseif ($comments == 1) {
    echo "1 comment";
 } else {
    echo "$comments comments";

But it is a great deal simpler to compromise and merely modify your presentation just a little to prevent the pluralization problem entirely:

 <span class="comment-count">
      Comments: <fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count>


 <span class="comment-count" title="Comments">
      <fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count>