Get Post Comments count

Try this one

<?php
$num_comments = get_comments_number(); // for some reason get_comments_number only returns a numeric value displaying the number of comments
if ( comments_open() ){
if($num_comments == 0){
$comments = __(‘No Comments’);
}
elseif($num_comments > 1){
$comments = $num_comments. __(‘Comments’);
}
else{
$comments =”1 Comment”;
}
$write_comments = ‘<a href=”‘ . get_comments_link() .'”>’. $comments.'</a>’;
}
else{$write_comments =  __(‘Comments are off for this post’);}

?>

now use $num_comments just like

<?php echo $num_comments; ?>

 

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: