返回介绍

get_comments_number_text()

发布于 2017-09-10 23:02:58 字数 3517 浏览 1053 评论 0 收藏 0

get_comments_number_text( string $zero = false,  string $one = false,  string $more = false )

Display the language string for the number of comments the current post has.


description


参数

$zero

(string) (Optional) Text for no comments.

Default value: false

$one

(string) (Optional) Text for one comment.

Default value: false

$more

(string) (Optional) Text for more than one comment.

Default value: false


源代码

File: wp-includes/comment-template.php

function get_comments_number_text( $zero = false, $one = false, $more = false ) {
	$number = get_comments_number();

	if ( $number > 1 ) {
		if ( false === $more ) {
			/* translators: %s: number of comments */
			$output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
		} else {
			// % Comments
			/* translators: If comment number in your language requires declension,
			 * translate this to 'on'. Do not translate into your own language.
			 */
			if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
				$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
				$text = preg_replace( '/&.+?;/', '', $text ); // Kill entities
				$text = trim( strip_tags( $text ), '% ' );

				// Replace '% Comments' with a proper plural form
				if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
					/* translators: %s: number of comments */
					$new_text = _n( '%s Comment', '%s Comments', $number );
					$new_text = trim( sprintf( $new_text, '' ) );

					$more = str_replace( $text, $new_text, $more );
					if ( false === strpos( $more, '%' ) ) {
$more = '% ' . $more;
					}
				}
			}

			$output = str_replace( '%', number_format_i18n( $number ), $more );
		}
	} elseif ( $number == 0 ) {
		$output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
	} else { // must be one
		$output = ( false === $one ) ? __( '1 Comment' ) : $one;
	}
	/**
	 * Filters the comments count for display.
	 *
	 * @since 1.5.0
	 *
	 * @see _n()
	 *
	 * @param string $output A translatable string formatted based on whether the count
	 *                       is equal to 0, 1, or 1+.
	 * @param int    $number The number of post comments.
	 */
	return apply_filters( 'comments_number', $output, $number );
}

更新日志

Versiondescription
4.0.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: _n()
  • wp-includes/l10n.php: _x()
  • wp-includes/l10n.php: __()
  • wp-includes/functions.php: number_format_i18n()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/comment-template.php: get_comments_number()
  • wp-includes/comment-template.php: comments_number
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/comment-template.php: comments_number()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文