워드프레스에서 댓글 숫자 보여주기
functions.php에 아래 소스 추가
//포스트에서 댓글 숫자 가져오기
$num_comments = get_comments_number(); // get_comments_number returns only a numeric value
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.’);
}
보여주고자 하는 곳에 아래 소스 추가
댓글 <?php comments_number( ‘0개’, ‘1개’, ‘%개’ ); ?>