WordPress + Facebook评论添加(需要php知识)


WordPress + Facebook comments addition (php knowledge needed)

我成功地通过这个函数获取了 Facebok 评论号:

<?php 
function fb_comment_count() { 
global $post; 
$url = get_permalink($post->ID); 
$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url); 
$json = json_decode($filecontent); 
$count = $json->$url->comments; 
if ($count == 0 || !isset($count)) { 
    $count = 0; 
} 
echo $count; 
} 
;?>

我用:

<?php fb_comment_count();?>

现在如何将其添加到此代码中:

<?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments'), '', __('Comments Closed') ); ?>

这样WordPress就在一个数字中显示WP和FB评论的数量。

非常感谢大家!

将 fb_comment_count 函数的最后一行更改为 return $count; 。这样你就有一个数字要处理。

现在在循环中,添加以下内容:

<?php 
$fb_comments = fb_comment_count();
$wp_comments = get_comments_number();
$total_comments = $fb_comments + $wp_comments;
printf ("<p>There are %d Total Comments: %d Wordpress Comments + %d Facebook Comments</p>'n",
        $total_comments, $wp_comments, $fb_comments );
 ?>

您还可以使用此代码段在您的帖子/页面上获得评论

<fb:comments-count href="<?php the_permalink(); ?>"></fb:comments-count></div>