不要反击股票

时间:2016-05-22 19:36:57

标签: javascript ajax wordpress

我需要为每个记录分享facebook

引入类别

我把这段代码:

    <?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;
?>

我出去的是什么: http://i.stack.imgur.com/B17V4.png

计数器只出现在一个地方。 如果他参与该类别的每一项记录,请告诉我该怎么做?

这里的字符串会产生错误。这段代码我在content.php中注册 http://i.stack.imgur.com/wyUtV.png

1 个答案:

答案 0 :(得分:0)

将此部分移动到主题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;
}

在content.php中只放了这个部分

<?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;
?> 

它会起作用。已经过测试。