WordPress Facebook评论计数存档

时间:2015-03-03 05:36:07

标签: php wordpress facebook

我想在我的博客档案中显示Facebook评论数。

我的wordpress网站在 function.php

中有以下php功能
    // Get combined FB and WordPress comment count
    function full_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;
    $wpCount = get_comments_number();
    $realCount = $count + $wpCount;
    if ($realCount == 0 || !isset($realCount)) {
        $realCount = 0;
    }
    return $realCount;
    }

这就是我在循环<?php echo full_comment_count(); ?>

中的模板文件上使用该函数的方法

大多数时候,大多数文章都会显示“0”评论。但有时候其中一个或两个有效。我做错了什么

1 个答案:

答案 0 :(得分:0)

试试这个

function full_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;
}