weixin_33736832 2016-05-22 19:36 采纳率: 0%
浏览 27

如果在每一类别里都有记录?

我需要为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

其中,counter只出现在了一个地方。告诉我,如果我想它在每一类别里都有记录的话,该怎么做?

下面是字符串产生错误的原因,是我在内容中注册的代码:http://i.stack.imgur.com/wyUtV.png

  • 写回答

1条回答 默认 最新

  • weixin_33743703 2016-05-23 00:30
    关注

    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.

    评论

报告相同问题?