Marat Petrov Marat Petrov - 6 months ago 45
Ajax Question

don't work counter share

I need to bring in the category for each record number of share facebook

I put this code:

<?php
function getFacebookDetails($url){
$rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=".urlencode($url);
$json = json_decode(file_get_contents($rest_url),true);
return $json;
}
$data = getFacebookDetails("http://mycodingtricks.com/html5/html5-inline-edit-with-mysql-php-jquery-and-ajax/");
$shares = $data[0]['share_count'];
$comments = $data[0]['comment_count'];
$likes = $data[0]['like_count'];
echo "Total Shares: ".$shares;
echo "Total Likes: ".$likes;
echo "Total Comments: ".$comments;
?>


that's what I go out:
http://i.stack.imgur.com/B17V4.png

counter appeared only in one place.
tell me how to do that had he been in every record in the category?

here's what the string produces errors. This code I registered in content.php
http://i.stack.imgur.com/wyUtV.png

Answer

Move this part to your themes functions.php

function getFacebookDetails($url){
    $rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=".urlencode($url);
    $json = json_decode(file_get_contents($rest_url),true);
return $json;
}

In the content.php just put this part

<?php
$link = get_permalink();
$data = getFacebookDetails($link);
$shares = $data[0]['share_count'];
$comments = $data[0]['comment_count'];
$likes  = $data[0]['like_count'];
echo "Total Shares: ".$shares;
echo "Total Likes: ".$likes;
echo "Total Comments: ".$comments;
?> 

It will work. Already tested.

Comments