How to get number of comments per post in wordpress?
How to get number of comments per post in wordpress?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
$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.');
}