链接按钮网址计数php和wordpress

时间:2015-03-09 13:40:34

标签: php wordpress facebook

我在我的wordpress中有一个功能,它在我身后的facebook晒黑数字,它给我带来了一些帖子的数量!我试图解决这个问题,更多的是给出错误,我需要帮助!

遵循功能:

function ia_fb_count($url_post) {
//Get the transient value from database
$fbcount = get_transient( 'fblcount' );
    if ( empty( $fbcount ) ){
        //If no value stored, get the like count
        $file = file_get_contents('http://graph.facebook.com/?ids="$url_post"');
            $jd = json_decode($file);
            $fbcount = number_format($jd->{'likes'});

        // Set the facebook likes transient value for 24 Hours
        set_transient('fblcount', $fbcount, 60*60*24 );
        // Also, return it at the same time
        return $fbcount;
    } else {
        // Transient Value is present, return it
        return $fbcount;
    }

}

在我的主题中调用函数,如下所示:

<?php
                $url_post = the_permalink(); 
                echo ia_fb_count($url_post);?>

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

这一行很可疑:

$file = file_get_contents('http://graph.facebook.com/?ids="$url_post"');

可能应该是

$file = file_get_contents('http://graph.facebook.com/?ids="'.$url_post.'"');

对于计算喜欢,分享或评论,您也可以尝试第三方解决方案。 Facebook Analytics是免费的,可以使用WordPress。