utnalove
08-17-2012, 09:32 PM
Hi, I am using the following code:
<a href="<?php comments_link(); ?>"><?php
$commentCount = full_comment_count();
if ( $commentCount == 0 ) {
echo 'add a comment';
}
else if ( $commentCount == 1 ) {
echo 'comment';
}
else {
echo '' . $commentCount . ' comments';
}
?></a>
and this code:
// 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;
}
Problem explained:
If there are 2 FB comments and 3 WP the output is: 5 comments
If there are no comments the output is:add a comment
If there are 0 FB comments and 1 WP the output is: comment
In the last example is missing the number 1.
Anybody can find the error in the code?
<a href="<?php comments_link(); ?>"><?php
$commentCount = full_comment_count();
if ( $commentCount == 0 ) {
echo 'add a comment';
}
else if ( $commentCount == 1 ) {
echo 'comment';
}
else {
echo '' . $commentCount . ' comments';
}
?></a>
and this code:
// 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;
}
Problem explained:
If there are 2 FB comments and 3 WP the output is: 5 comments
If there are no comments the output is:add a comment
If there are 0 FB comments and 1 WP the output is: comment
In the last example is missing the number 1.
Anybody can find the error in the code?