【问题标题】:Automatically close comments on PAGES older than X days自动关闭超过 X 天的 PAGES 上的评论
【发布时间】: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 发布。

谢谢。

【问题讨论】:

  • 该代码取决于许多选项。你在帖子上也设置了这些吗?
  • 我正在关闭和打开帖子讨论设置以检查差异 - 并意识到在将代码保存到功能页面后我没有重新打开它。现在可以了。哦!谢谢。

标签: php wordpress comments


【解决方案1】:

  1. 转到您的帖子页面
  2. 展开屏幕选项部分
  3. 更改选项,让屏幕上的帖子数量可观
  4. 应用屏幕选项更改
  5. 选择所有帖子
  6. 在批量选项下拉菜单中选择“编辑”。
  7. 将“cmets”设置为“不允许”(禁用评论)
  8. 将“ping”设置为“不允许”(禁用 pingback)
  9. 点击“更新”按钮。

如果您没有将屏幕选项设置得足够高以显示所有帖子,那么您需要对所有帖子的“第 2 页”(以及 3…4.. 等)重复上述操作

关闭 ping 有助于减少进入 WordPress 安装的垃圾邮件数量,即使您使用的是 Disqus 或 akismet。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
  • 2018-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多