归档

2015-03-03 211 views
1

WordPress的Facebook的评论计数我想显示在我的博客档案Facebook的评论数。归档

我的WordPress网站在function.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函数这是我如何使用功能上的模板文件中的循环<?php echo full_comment_count(); ?>

大部分时间内最的文章显示“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; 
} 
+0

所有计数被设置为0 ...我用它的网站是www.womenoffaith.com在博客归档......任何理论? – Omar 2015-03-04 04:24:41

+0

参考http://screencast.com/t/NEfpNJ06rl72。所有评论数显示正常。分享您正在面对问题的网址。 – Karthikeyani 2015-03-05 04:48:24