Z-BlogPHP主题评论模块开发二,后端模版部分

作者: JONE 分类: PHPer 发布时间: 2020-04-08 14:02

评论功能模版分为4个部分

  1. comment.php 评论区模板
  2. comments.php 每条评论内容显示模板
  3. commentpost.php 评论发送表单模板
  4. commentreply.php 回复的评论内容显示模版

comment.php示例代码PHP

<li class="comment-content">
    <span class="comment-f">#{$comment.FloorID}</span>
    <div class="comment-main">
            <p>
                <a class="address" href="{$comment.Author.HomePage}" rel="nofollow"  target="_blank"><strong>{$comment.Author.StaticName}</strong></a>
                <span class="time">({$comment.Time()})</span><br>
                {$comment.Content}<br>
                <a style="color: #c0c0c0" href="#comment" onclick="zbp.comment.reply('{$comment.ID}')" class="reply">回复</a>
            </p>
    </div>

</li>

{foreach $comment.Comments as $comment}
{template:commentreply}
{/foreach}

comments.php示例代码PHP

<div class="title" id="comment">
    <h3>评论</h3>
</div>
<div id="respond">
    {template:commentpost}

</div>
<div id="postcomments">
    <ol id="comment_list" class="commentlist">
        {foreach $comments as $key => $comment}
            {template:comment}
        {/foreach}
    </ol>
    <!--评论翻页条输出-->
    <div>
        {if $pagebar && $pagebar.PageAll > 1}
        {foreach $pagebar.buttons as $k => $v}
        {if $pagebar.PageNow==$k}
        <span class="now-p">{$k}</span>
        {elseif $pagebar.PageNow+1==$k}
        <span class="next-p"><a href="{$v}">{$k}</a></span>
        {else}
        <a href="{$v}">{$k}</a>
        {/if}
        {/foreach}
        {/if}
    </div>
    <label id="AjaxCommentEnd"></label><!--评论输后必须的label-->
</div>

commentpost.php示例代码PHP

<div class="comment" id="comments">
       <form id="frmSumbit" target="_self" name="comment-form" 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}
       <input  name="inpName" id="inpName"  class="form-control" size="22" placeholder="您的昵称(必填)" maxlength="15"  tabindex="1"  value="{$user.Name}" >
       <input  name="inpEmail" id="inpEmail" class="form-control" size="22" placeholder="您的邮箱(必填)" maxlength="58"  tabindex="2" value="{$user.Email}">
       <input  name="inpHomePage" id="inpHomePage" class="form-control" size="22" placeholder="您的网址(非必填)" maxlength="58"  tabindex="2" value="{$user.HomePage}">
           {if $option['ZC_COMMENT_VERIFY_ENABLE']}    <div>
               <label for="inpVerify">验证码(*)</label>
               <input type="text" name="inpVerify" id="inpVerify" class="text" value="" />
               <img style="width:{$option['ZC_VERIFYCODE_WIDTH']}px;height:{$option['ZC_VERIFYCODE_HEIGHT']}px;cursor:pointer;" src="{$article.ValidCodeUrl}" alt="" title="" onclick="javascript:this.src='{$article.ValidCodeUrl}&tm='+Math.random();"/>
           </div>
           {/if}
       {/if}


       <div class="comment-box">
           <textarea placeholder="您的评论或留言(必填)" name="txaArticle" id="txaArticle" cols="100%" rows="3" tabindex="3"></textarea>

           <div class="comment-ctrl">
               <div class="comment-prompt" style="display: none;">
                   <i class="fa fa-spin fa-circle-o-notch"></i> <span class="comment-prompt-text">评论正在提交中...请稍后</span>
               </div>

               <div class="comment-success" style="display: none;">
                   <i class="fa fa-check"></i> <span class="comment-prompt-text">评论提交成功...</span>
               </div>

               <button type="submit" name="comment-submit" id="comment-submit" tabindex="4" onclick="return zbp.comment.post()">评论</button>

               <a id="cancel-reply" style="display: none">取消回复</a>

           </div>
       </div>
       </form>
</div>

commentreply.php示例代码PHP

    <li class="comment-content"  style="padding-left: {$comment.Level*20}px">

        <div class="comment-main">
            <p>
                <a class="address" href="#" rel="nofollow" target="_blank">{$comment.Author.StaticName}</a>
                <span class="time">({$comment.Time()})</span><br>
                {$comment.Content}<br>
                <a style="color: #c0c0c0"  href="#comment" onclick="zbp.comment.reply('{$comment.ID}')" class="reply">回复</a>
            </p>
        </div>

    </li>


{foreach $comment.Comments as $comment}
    {template:commentreply}
{/foreach}

参考教材