Posted By

bitsculptor on 08/23/13


Tagged

comments facebook


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fhenderson


Facebook Comments for Wordpress


 / Published in: PHP
 

URL: http://wp.tutsplus.com/tutorials/the-ultimate-guide-to-implementing-facebook-comments-on-your-blog/

This is the code to add facebook comments to your wordpress site.

  1. <div id="fb-root"></div>
  2. <script>(function(d, s, id) {
  3. var js, fjs = d.getElementsByTagName(s)[0];
  4. if (d.getElementById(id)) return;
  5. js = d.createElement(s); js.id = id;
  6. js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Your App ID Here";
  7. fjs.parentNode.insertBefore(js, fjs);
  8. }(document, 'script', 'facebook-jssdk'));</script>
  9.  
  10. <meta property="fb:app_id" content="Your App ID Here"/>
  11.  
  12. <div class="fb-comments" data-href="<?php the_permalink() ?>" data-num-posts="2" data-width="470" data-colorscheme="light" data-mobile="false"></div>
  13.  
  14.  
  15. // Get combined FB and WordPress comment count
  16. function get_full_comment_count() {
  17. global $post;
  18. $url = get_permalink($post->ID);
  19.  
  20. $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
  21. $json = json_decode($filecontent);
  22. $count = $json->$url->comments;
  23. $wpCount = get_comments_number();
  24. $realCount = $count + $wpCount;
  25. if ($realCount == 0 || !isset($realCount)) {
  26. $realCount = 0;
  27. }
  28. return $realCount;
  29. }
  30. function the_full_comment_count() {
  31. $realCount = get_full_comment_count();
  32. echo $realCount;
  33. }

Report this snippet  

You need to login to post a comment.