二十、Wordpress评论模版调用和评论输入窗口

comments_template() //调用评论模板
comments_open() //判断是否开启了评论功能,返回true和false,(默认开启,关闭功能在后台新建文章页面内)

post_password_required() //判断查看该文章是否需要密码(该文章必须开启了评论功能)

have_comments() //判断当前文章是否有评论
wp_list_comments() //输出当前文章所有评论
is_user_logged_in() //判断用户是否登陆
comment_form() //输出写评论窗口
用户必须登陆才能评论:

头像功能:默认开通
在国内即便开启了头像功能也不一定能够显示头像,因为可能被墙,所以需要gravatat-fixed、googlefontsto360这两个插件来解决。

实例:在文章模板single.php或者单页模板page.php内引入评论模板
<?php comments_template(); ?> //引入评论模板
comments.php //评论页面模板(约定的名称)
<div id="comment-box">
<h3>评论</h3>
<ol class="commentlist">
<? if ( !comments_open() ) { ?> //判断是否开启了评论功能
<li class="tip-box"><p>评论功能已经关闭!</p></li>
<? } else if ( post_password_required() ) { ?> //判断查看该文章是否需要密码
<li class="tip-box"><p>请输入密码再查看评论内容!</p></li>
<? } else if ( !have_comments() ) { ?> //判断该文章是否有评论
<li class="tip-box"><p><a href="#respond">还没有任何评论,你来说两句吧</a></p></li>
<? } else { wp_list_comments(); } ?> //输出当前文章评论
</ol>
<div class="clr"></div>
<div class="clr"></div>
//判断options数据表里的comment_registration值 //判断用户是否登陆
<? if ( get_option('comment_registration') && !is_user_logged_in() ) { ?>
//登陆的链接 //登陆后跳转的链接,()为空表示当前页面
<p>你必须 <a href="<? echo wp_login_url( get_permalink() ); ?>">登录</a> 才能发表评论.</p>
//判断评论是否开启 //输出写评论的窗口
<? } else if( comments_open() ){ comment_form(); } ?>
</div>