【发布时间】:2015-08-14 04:13:09
【问题描述】:
我想在时间流逝后禁用 WordPress 页面上的 cmets,就像我可以使用设置 > 讨论对帖子/文章执行的操作一样。
经过几个小时的谷歌搜索,我发现了这个链接 http://premium.wpmudev.org/blog/how-to-stop-comments-on-your-wordpress-posts/
...有我添加到我的子functions.php的这段代码:
function check_comments_open() {
global $post;
// if the post comment status is not open then no need to worry
if ( $post->comment_status != 'open' ) return false;
// if not closing comments on old posts then also don't worry
if ( !get_option('close_comments_for_old_posts') ) return $post->comment_status;
// calculate the age (in days) of the post
$post_date = date_create( $post->post_date );
$today = date_create();
$age = date_interval_format( date_diff( $post_date , $today ) , '%a' );
// if the post is older than the 'close after x days' then close comments
if ( $age > get_option('close_comments_days_old') ) {
return false;
} else {
return true;
}
}
add_filter( 'comments_open' , 'check_comments_open' );
这不起作用(使用自定义的 21 主题)。读者仍然有机会在所有允许使用 cmets 的页面上添加评论。并非所有页面都有 cmets。我们希望能够保留这些 cmets,但阻止新的 cmets 发布。
谢谢。
【问题讨论】:
-
该代码取决于许多选项。你在帖子上也设置了这些吗?
-
我正在关闭和打开帖子讨论设置以检查差异 - 并意识到在将代码保存到功能页面后我没有重新打开它。现在可以了。哦!谢谢。