How to get number of comments per post in wordpress?

How to get number of comments per post in wordpress?

Team Leader Asked on March 4, 2017 in WORDPRESS.
Add Comment
1 Answer(s)

$num = get_comments_number(); // Returns only a numeric value
if ( comments_open() ) {

if ( $num == 0 ) {

$comments = __('No Comments');

} elseif ( $num > 1 ) {

$comments = $num . __(' Comments');

} else {

$comments = __('1 Comment');

}

$write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';

} else {

$write_comments =  __('Comments are off for this post.');

}

Team Leader Answered on March 5, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.