WordPress + Facebook comments addition (php knowledge needed)
Posted
by
user1356223
on Stack Overflow
See other posts from Stack Overflow
or by user1356223
Published on 2012-04-27T13:50:15Z
Indexed on
2012/09/17
9:38 UTC
Read the original article
Hit count: 270
I succeded to fetch Facebok comments number via this function:
<?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;
}
;?>
And I call it with:
<?php fb_comment_count();?>
Now how do I add it to this code:
<?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments'), '', __('Comments Closed') ); ?>
so that WordPress shows number of WP and FB comments together in one number.
Thank you very much to everyone!
© Stack Overflow or respective owner