显示指向当前帖子ID的注释的链接。
原型
comments_popup_link( string $zero = false, string $one = false, string $more = false, string $css_class = '', string $none = false )
参数
$zero
(string)
(Optional)
没有注释时显示的字符串。
$one
(string)
(Optional)
仅有一个注释可用时显示的字符串。
$more
(string)
(Optional)
有多个注释时要显示的字符串。
$css_class
(string)
(Optional)
用于评论的CSS类。
$none
(string)
(Optional)
注释关闭后显示的字符串。
源文件
路径:wp-includes/comment-template.php
<?php
...
function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
$id = get_the_ID();
$title = get_the_title();
$number = get_comments_number( $id );
if ( false === $zero ) {
/* translators: %s: post title */
$zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title );
}
if ( false === $one ) {
/* translators: %s: post title */
$one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title );
}
if ( false === $more ) {
/* translators: 1: Number of comments 2: post title */
$more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
$more = sprintf( $more, number_format_i18n( $number ), $title );
}
if ( false === $none ) {
/* translators: %s: post title */
$none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );
}
if ( 0 == $number && !comments_open() && !pings_open() ) {
echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
return;
}
if ( post_password_required() ) {
_e( 'Enter your password to view comments.' );
return;
}
echo '<a href="';
if ( 0 == $number ) {
$respond_link = get_permalink() . '#respond';
/**
* Filters the respond link when a post has no comments.
*
* @since 4.4.0
*
* @param string $respond_link The default response link.
* @param integer $id The post ID.
*/
echo apply_filters( 'respond_link', $respond_link, $id );
} else {
comments_link();
}
echo '"';
if ( !empty( $css_class ) ) {
echo ' class="'.$css_class.'" ';
}
$attributes = '';
/**
* Filters the comments link attributes for display.
*
* @since 2.5.0
*
* @param string $attributes The comments link attributes. Default empty.
*/
echo apply_filters( 'comments_popup_link_attributes', $attributes );
echo '>';
comments_number( $zero, $one, $more );
echo '</a>';
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/comments_popup_link/