WordPress评论模块实现登录可见方法

无评论

作者照片

By 霜天

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

打开主题正文模板文件single.php,找到类似的:

if ( comments_open() || get_comments_number() ) :

comments_template();

endif;

修改为:

if ( is_user_logged_in()){

if ( comments_open() || get_comments_number() ) :

comments_template();

endif;

}

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

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

<?php if ( is_user_logged_in()){ ?>

<?php if ( comments_open() || get_comments_number() ) : ?>

<?php comments_template( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, true ); ?>

<?php endif; ?>

<?php } ?>

发表评论