当前浏览:首页 / WordPress函数 / comments_popup_link()

comments_popup_link( false|string $zero = false, false|string $one = false, false|string $more = false, string $css_class = '', false|string $none = false )

显示指向当前文章ID的评论的链接

comment 评论more...

linkmore...

popup


参数

$zero

(false|string)(可选) 无评论时显示的字符串。

默认值: false

$one

(false|string)(可选) 只有一条评论可用时显示的字符串。

默认值: false

$more

(false|string)(可选) 当有多个评论时显示的字符串。

默认值: false

$css_class

(string)(可选) 用于评论的CSS类。

默认值: ''

$none

(false|string)(可选) 关闭评论时显示的字符串。

默认值: false



源码

查看源码 官方文档


更新日志

版本描述
0.71开始引入

使用示例

  • 示例1

    根据评论条件加载不同的CSS类
    如果要将不同的类加载到comments_popup_link(),请使用以下命令:

    $css_class = 'zero-comments';
    $number    = (int) get_comments_number( get_the_ID() );
    
    if ( 1 === $number )
    	$css_class = 'one-comment';
    elseif ( 1 < $number )
    	$css_class = 'multiple-comments';
    
    comments_popup_link( 
    	__( 'Post a Comment', 'wpdocs_textdomain' ), 
    	__( '1 Comment', 'wpdocs_textdomain' ), 
    	__( '% Comments', 'wpdocs_textdomain' ),
    	$css_class,
    	__( 'Comments are Closed', 'wpdocs_textdomain' )
    );
    
    
  • 示例2

    评论数量的本地化文本响应

    显示评论弹出链接,使用“No comments yet”表示无评论,使用“1 comment”表示一条评论,使用“% comments”表示多条评论(%替换为评论条数),如果禁用评论,则使用“comments are off for this post”。此外,comments link是用于链接的自定义CSS类。

    <?php comments_popup_link( __( 'Leave a comment', 'text-domain' ), __( '1 Comment', 'text-domain' ), __( '% Comments', 'text-domain' ) ); ?>
  • 示例3

    评论数量的文本响应
    显示评论弹出链接,对于没有评论,使用“No comments yet”,对于一条评论,使用“1 comment”,对于一条以上的评论,使用“% comments”(%替换为评论条数),如果评论被禁用,则显示“评论关闭”。此外,comments-link是链接的自定义CSS类。

    <p>
    <?php
    comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments are off for this post');
    ?>
    </p>
    
    
  • 示例4

    禁用评论时隐藏评论链接
    当在文章编辑界面中关闭评论时,隐藏段落元素 <p></p> 它包含comments_popup_link>。对于那些想逐篇文章启用/关闭评论的人来说,这很好。必须在循环中使用。

    <?php
    if ( comments_open() ) :
    	echo '<p>';
    	comments_popup_link( 'No comments yet', '1 comment', '% comments', 'comments-link', 'Comments are off for this post');
    	echo '</p>';
    endif;
    ?>