Question

So what i have in mind is showing a list with most popular posts based on how many facebook comments they have. I already managed to make a function that counts based facebook graph how many comments a post has, but i am having problem with the query:

function fb_comment_count() {
global $post;
$url = get_permalink($post->ID);

$filecontent = file_get_contents('http://graph.facebook.com/?ids=' . $url);
$json = json_decode($filecontent);
$count = $json->$url->comments;
if ($count == 0 || !isset($count)) {
    $count = 0;
} ?>

<?php if ($count == 0) { ?>
         <span>No comment</span>
<?php } elseif ($count == 1) { ?>
         <span>One Comment</span>
<?php } elseif ($count > 1 ) { ?>
         <span><?php echo $count; ?> Comments</span>

Thanks!

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top