WordPress正常是可以设置登录发表评论,但是也有人需要实现评论模块在登录状态下可见,今天为大家分享一个WordPress评论模块实现登录可见方法,这里我们要用到WordPress判断是否登录的函数:is_user_logged_in(),用判断函数把评论模块包裹起来就行了。

打开主题正文模板文件single.php,找到类似的:
if ( comments_open() || get_comments_numbej ) J ~ q 7 v !r() ) :
comJ T Qments_template();
endif;
修改为:
if ( is_user_loB A 3 { a rgged_in()){
if ( comments_open() || get_comments_numbZ J } E O . / Rer() ) :
comments_template();
endiD v 4 \ /f;
}
之后,只有登录的状态下才能看见评论模块及评论内容。
其它主题方法类似q d –,比如:
<4 t l G =?php if ( is_user_logged_in()){ ?>
<?php if ( comments_open() || get_comments_number() ) : ?>
<?php comments_template( ”, true ); ?>
<?php endif; ?>
<?php } ?>

