超过限制天数后自动关闭WordPress文章的评论功能,是一个限制评论的好方法,当评论达到一定数量后自动关闭WordPress文章的评论功能,这也是一个不错的选择哦!
将下面的代码添加主题的 functions.php 文件即可:
//评论超过一定数量关闭评论
function disable_comments( $posts ) {
if ( !is_single() ) {
return $posts;
}
if ( $posts[0]->comment_count > 100 ) {
$posts[0]->comment_status = 'disabled';
$posts[0]->ping_status = 'disabled';
}
return $posts;
}
add_filter( 'the_posts', 'disable_comments' ); |
//评论超过一定数量关闭评论
function disable_comments( $posts ) {
if ( !is_single() ) {
return $posts;
}
if ( $posts[0]->comment_count > 100 ) {
$posts[0]->comment_status = 'disabled';
$posts[0]->ping_status = 'disabled';
}
return $posts;
}
add_filter( 'the_posts', 'disable_comments' );
上面的代码是当一篇文章的评论数量超过100条以后,自动关闭这篇文章的评论功能,请根据自己的需要,修改第 6 行的 100 为你想要的数量。
此代码在 WP 3.5.1 测试有效。
参考资料:http://wordpressapi.com/2013/06/12/disable-comments-posts-commment-count-wordpress/
来源:
https://www.wpdaxue.com/disable-comments-after-commment-count.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33210.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57