WordPress實現登錄可見評論模塊

下面由WordPress教程欄目給大家介紹wordpress實現登錄可見評論模塊的方法,希望對需要的朋友有所幫助!

WordPress實現登錄可見評論模塊

WordPress正常可以設置登錄發表評論,但不登錄也可以正常看到留言評論內容,最近有用戶說接到通知個人備案的網站不允許有評論互動功能,雖然我沒接到過通知,但可以簡單修改一下模板,讓主題評論模塊只有在登錄的狀態下可見。

wordpress教程登錄可見評論模塊WordPress 登錄可見評論模塊

這里我們要用到WordPress判斷是否登錄的函數:is_user_logged_in()

用判斷函數把評論模塊包裹起來就行了。

以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; }

之后,只有登錄的狀態下才能看見評論模塊及評論內容。

其它主題方法類似,比如:

<?php  if ( is_user_logged_in()){ ?><?php  if ( comments_open() || get_comments_number() ) : ?><?php  comments_template( &#39;&#39;, true ); ?><?php  endif; ?><?php  } ?>

? 版權聲明
THE END
喜歡就支持一下吧
點贊13 分享