How to get Facebook comments count with HTML5?

I know two ways to retrieve the number of comments on Facebook:

<fb:comments-count href=http://example.com/></fb:comments-count> awesome comments 

and...

<iframe src="http://www.facebook.com/plugins/comments.php?href=example.com&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:16px;" allowTransparency="true"></iframe> 

But none is a semantics for HTML5 solution, is there any alternative?

Answers


You can also get HTML5 valid FB comment count this way:

<div class="fb-comments-count" data-href="/post URL">0</div>

FB automatically replaces the "0" with the correct number. If you put something there like "awesome comments", it will be replaced with the number of comments i.e. "13", etc.

In order to get the number and use your own text, do something like this:

<a href="/post URL"><div class="fb-comments-count" data-href="/post URL">0</div> awesome comments</a>

Notice you must wrap your class in div's or else the comment counter will not work.


Graph API example using jquery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){

    $.ajax({
        url: 'http://graph.facebook.com/http://www.google.com',
        dataType: 'jsonp',
        success: function(data) {
             alert("comments: " + data.comments);
       }
    });

});
</script>

Since v2.3, it can be handled by span, which already has the natively display: inline; semantics.

<a href="/post-link">
  <span class="fb-comments-count" data-href="/post-link">0</span> comments
</a>

For an wordpress post u can use like <fb:comments-count href=<?php the_permalink();?>></fb:comments-count> awesome comments


Need Your Help

ASP.MVC: Repository that reflects IQueryable but not Linq to SQL, DDD How To question

linq-to-sql repository domain-driven-design iqueryable

I want to create a DDD repository that returns IQueryable Entities that match the Linq to SQL underlying classes, minus any relations. I can easily return Entities minus the relations with a Linq ...

How can Meteor apps be tested?

testing meteor tdd

What are the recommended ways to test web applications developed with the meteor framework?