为 WordPress 设置评论模块登录可见

  • 时间:2020-05-17 12:16:18
  • 分类:网络文摘
  • 阅读:133 次

对于 wordpress 而言,虽然可以设置登录才能发表评论,但用户如果不登录,也可以正常浏览其他人的留言评论内容。据说现在个人备案的网站不允许有评论互动功能,我们可以简单修改一下wordpress主题,让wordpress的评论模块只有在登录状态下才可见。

这里需用到 WordPress 判断是否登录的函数:is_user_logged_in()

用判断函数把评论模块包裹起来就行了。

以 WordPress 默认主题 Twenty Seventeen 为例,打开主题正文模板文件 single.php,找到类似的:

  1. if ( comments_open() || get_comments_number() ) :
  2.     comments_template();
  3. endif;

修改为:

  1. if ( is_user_logged_in()){
  2.     if ( comments_open() || get_comments_number() ) :
  3.         comments_template();
  4.     endif;
  5. }

之后,只有在登录状态下才能看见评论模块及评论内容。

其它主题方法类似,比如:

  1. <?php if ( is_user_logged_in()){ ?>
  2. <?php if ( comments_open() || get_comments_number() ) : ?>
  3.     <?php comments_template( '', true ); ?>
  4. <?php endif; ?>
  5. <?php } ?>

原文:https://zmingcx.com/wordpress-login-visible-comments.html

推荐阅读:
In-place Run-Length String Compressions using C++  Algorithms to Compute the Factor Combinations for An Integer usi  How and Why You Should Use Infographics On Your Blog  How to Make Your “Contact Us” Page Kick Ass  The A to Z of Content Marketing: Habits Every Content Marketer S  Keeping the Flame Going: How to Rock a Steady Job and Still Have  How to Use Social Media and User-Generated Content to Boost Traf  7 Types of Blog Posts and When to Use Them  How to Maximize Profit From Your Blog Visitors  Win a Premium WordPress Theme For Your Blog 
评论列表
添加评论