Facebook Comments for Wordpress


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

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.