Hi,
Let’s say you have a Facebook page and you want to know how many likes / shares / comments does the current blog post has. I made a script, based on this article, which allows you so see how many likes / shares / comments a blog post has.
It will give you an information like this:
How to do it? You should add the following code:
if( current_user_can('administrator') ) {
$source_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$rest_url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml_response = file_get_contents($rest_url);
$xml_record = simplexml_load_string($xml_response);
$fb_share_count = $xml_record->link_stat->share_count;
$fb_like_count = $xml_record->link_stat->like_count;
$fb_comment_count = $xml_record->link_stat->comment_count;
$fb_total = $xml_record->link_stat->total_count;
echo '<br/><br/><b>Administrator</b> information:<br/>';
echo 'Facebook Shares: '.$fb_share_count.'<br/>';
echo 'Facebook Likes: '.$fb_like_count .'<br/>';
echo 'Facebook Comments: '.$fb_comment_count .'<br/>';
in your single.php file (or wherever else you need it), to have it display the information as in the picture above.
Change the condition to
if( (current_user_can('administrator')) && (is_single()) )Â
, if you want to add the code to only launch if the current page is single (so, you can thus put the code in header.php or in footer.php or in sidebar.php).