Displays the total number of comments, Trackbacks, and Pingbacks for the current post. This tag must be within The Loop.

Use get_comments_number() to retrieve the value.

comments_number() 描述


 <?php comments_number$zero$one$more ); ?> 

comments_number() 用法



(string) (可选) Text to display when there are no comments.

默认值: 'No Comments'


(string) (可选) Text to display when there is one comment.

默认值: '1 Comment'


(string) (可选) Text to display when there is more than one comment. % is replaced by the number of comments, so '% so far' is displayed as "5 so far" when there are five comments.

默认值: '% Comments'

comments_number() 参数


Text Response to Number of Comments

Displays text based upon number of comments: Comment count zero - no responses; comment count one - one response; more than one comment (total 42) displays 42 responses.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */

  This post currently has
  <?php comments_number( 'no responses', 'one response', '% responses' ); ?>.

Title For Comments Section

You might want to have a title above your comments section that includes the number of comments. This example shows how to do that and have all the strings also be translatable.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */

printf( _nx( 'One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'textdomain' ), number_format_i18n( get_comments_number() ) );

comments_number() 示例


添加于 版本: 0.71

comments_number() 历史


comments_number() 函数的代码位于 wp-includes/comment-template.php

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */
 * Display the language string for the number of comments the current post has.
 * @since 0.71
 * @param string $zero       Optional. Text for no comments. Default false.
 * @param string $one        Optional. Text for one comment. Default false.
 * @param string $more       Optional. Text for more than one comment. Default false.
 * @param string $deprecated Not used.
function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '1.3' );
	echo get_comments_number_text( $zero, $one, $more );

comments_number() 源文件