核心提示:打開當前主題的functions.php文件,添加//評論超過一定數(shù)量關閉評論 function disable_comments( $posts ) { if ( !is_single() ) { return $posts; } if ( $posts[0]-comment_count50 ) …
打開當前主題的functions.php文件,添加
//評論超過一定數(shù)量關閉評論 function disable_comments( $posts ) { if ( !is_single() ) { return $posts; } if ( $posts[0]->comment_count > 50 ) { $posts[0]->comment_status = 'disabled'; $posts[0]->ping_status = 'disabled'; } return $posts; } add_filter( 'the_posts', 'disable_comments' );
123456789101112 //評論超過一定數(shù)量關閉評論function disable_comments( $posts ) {if ( !is_single() ) {return $posts;}if ( $posts[0]->comment_count > 50 ) {$posts[0]->comment_status = 'disabled';$posts[0]->ping_status = 'disabled';}return $posts;}add_filter( 'the_posts', 'disable_comments' );
其中,50可以修改成自己需要的數(shù)字,表示一篇文章的評論如果超過這個數(shù)值,則自動關閉評論。
未經(jīng)允許不得轉(zhuǎn)載:445IT之家 » wordpress:評論達到一定數(shù)量時自動關閉評論的設