在前面Z-Blog PHP主题模板教程中,post-single.php文件中已经加入调用评论comments.php代码,下面孤狼将分享有关评论comments.php文件使用其它文件和代码。同时前面已经分享了评论所使用的CSS样式。
——首先,新建三个文件,comments.php ;comment.php ;commentpost.php ;
——comments.php文件,写入以下代码。
PHP
{if $socialcomment}{$socialcomment}{else}<h3>{if $article.CommNums==0}没有评论,留下你的印记,证明你来过。{else}已有{$article.CommNums}条留言{/if}</h3><div class="clear"></div><label id="AjaxCommentBegin"></label>{foreach $comments as $key => $comment}{template:comment}{/foreach}<div class="commentpagebar">{template:pagebar}</div><label id="AjaxCommentEnd"></label>{template:commentpost}{/if}
——comment.php文件,写入以下代码。
PHP
<ul class="msg" id="cmt{$comment.ID}"><li class="msgname"><div class="avatar"><img src="{$comment.Author.Avatar}"/></div><div class="commentname"><a href="{$comment.Author.HomePage}" target="_blank">{$comment.Author.StaticName}</a> <span>{$comment.Time()} <a href="#comment" onclick="return zbp.comment.reply('{$comment.ID}')">回复该评论</a></span><div class="comment_text">{$comment.Content}</div></div></li>{foreach $comment.Comments as $comment}<li class="msgarticle">{template:comment}</li>{/foreach}</ul>
——commentpost.php文件,写入以下代码。
PHP
</br><div class="center-b"></div><div class="commentpost" id="comment">发表评论:{if $user.ID>0}{$user.StaticName}{/if}<a rel="nofollow" id="cancel-reply" href="#comment" style="display:none;"><small>取消回复</small></a><form id="frmSumbit" target="_self" method="post" action="{$article.CommentPostUrl}" ><input type="hidden" name="inpId" id="inpId" value="{$article.ID}" /><input type="hidden" name="inpRevID" id="inpRevID" value="0" />{if $user.ID>0}<input type="hidden" name="inpName" id="inpName" value="{$user.Name}" /><input type="hidden" name="inpEmail" id="inpEmail" value="{$user.Email}" /><input type="hidden" name="inpHomePage" id="inpHomePage" value="{$user.HomePage}" /> {else}<div class="input-t"><input type="text" name="inpName" id="inpName" value="{$user.Name}" tabindex="1" placeholder="名称(必填)"/><input type="text" name="inpEmail" id="inpEmail" value="{$user.Email}" tabindex="2" placeholder="邮箱"/><input type="text" name="inpHomePage" id="inpHomePage" value="{$user.HomePage}" onfocus="this.value='http://';" tabindex="3" placeholder="网址"/></div>{/if}<p><label for="content">正文(*)</label></p><p><textarea name="txaArticle" id="txaArticle" class="text" cols="50" rows="4" tabindex="5" ></textarea></p><p><input name="sumbit" type="submit" tabindex="6" value="提交" onclick="return zbp.comment.post()" class="button" /></p></form><p class="postbottom">◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。</p></div>
——完成。