我在我的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);?>
有人可以帮我吗?
这行是可疑的:
$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配合使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句