Facebook Comment Count

Final version of code used:

    function fb_comment_count($link = 'link') {
global $post;
$url="https://graph.facebook.com/";
$posturl = get_permalink($post->ID);
$url .= $posturl;

$filecontent = wp_remote_retrieve_body(wp_remote_get($url, array('sslverify'=>false)));
$json = json_decode($filecontent);
$count = $json->comments;
if ($count == 0 || !isset($count)) {
    $count = 0;
}

$comments = $count;
if ($count == 1) {
    $comments .= ' Comment';
}
elseif ($count == 0) {
    $comments="Leave a Comment";
}
elseif ($count > 1) {
    $comments .= ' Comments';
}
if ($link == 'nolink') {
    echo $comments;
}
else {
    echo '<a href="'.$posturl.'#comments" title="Comments for '.$post->post_title.'">'.$comments.'</a>';
}
}

Leave a Comment