参数
- $zero
-
(false|string)(可选) 无评论时显示的字符串。
默认值: false
- $one
-
(false|string)(可选) 只有一条评论可用时显示的字符串。
默认值: false
- $more
-
(false|string)(可选) 当有多个评论时显示的字符串。
默认值: false
- $css_class
-
(string)(可选) 用于评论的CSS类。
默认值: ''
- $none
-
(false|string)(可选) 关闭评论时显示的字符串。
默认值: false
源码
更新日志
版本 | 描述 |
---|---|
0.71 | 开始引入 |
使用示例
根据评论条件加载不同的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' ) );
评论数量的本地化文本响应
显示评论弹出链接,使用“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' ) ); ?>
评论数量的文本响应
显示评论弹出链接,对于没有评论,使用“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>
禁用评论时隐藏评论链接
当在文章编辑界面中关闭评论时,隐藏段落元素 <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; ?>