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