下面由WordPress教程欄目給大家介紹WordPress實現(xiàn)登錄可見評論模塊的方法,希望對需要的朋友有所幫助!
WordPress正常可以設(shè)置登錄發(fā)表評論,但不登錄也可以正??吹搅粞栽u論內(nèi)容,最近有用戶說接到通知個人備案的網(wǎng)站不允許有評論互動功能,雖然我沒接到過通知,但可以簡單修改一下模板,讓主題評論模塊只有在登錄的狀態(tài)下可見。
WordPress 登錄可見評論模塊WordPress 登錄可見評論模塊
這里我們要用到WordPress判斷是否登錄的函數(shù):is_user_logged_in()
用判斷函數(shù)把評論模塊包裹起來就行了。
以WordPress默認主題Twenty Seventeen為例,打開主題正文模板文件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; }
之后,只有登錄的狀態(tài)下才能看見評論模塊及評論內(nèi)容。
其它主題方法類似,比如:
<?php if ( is_user_logged_in()){ ?> <?php if ( comments_open() || get_comments_number() ) : ?> <?php comments_template( '', true ); ?> <?php endif; ?> <?php } ?>