0

模板类型:移植
模板问题:评论后不显示评论,后台也没有。

<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php function threadedComments($comments, $options) {
    $commentClass = '';
    if ($comments->authorId) {
        if ($comments->authorId == $comments->ownerId) {
            $commentClass .= ' comment-by-author';  //如果是文章作者的评论添加 .comment-by-author 样式
        } else {
            $commentClass .= ' comment-by-user';  //如果是评论作者的添加 .comment-by-user 样式
        }
    } 
    $commentLevelClass = $comments->_levels > 0 ? ' comment-child' : ' comment-parent';  //评论层数大于0为子级,否则是父级
?>

<li id="C-<?php $comments->theId(); ?>" class="C-li">
   <div class="DS-post">
      <a class="user" href="http://aklis.info" target="_blank">
          <?php
            //头像CDN by Rich
            $host = 'https://secure.gravatar.com'; //自定义头像CDN服务器
            $url = '/avatar/'; //自定义头像目录,一般保持默认即可
            $size = '32'; //自定义头像大小
            $rating = Helper::options()->commentsAvatarRating;
            $hash = md5(strtolower($comments->mail));
            $avatar = $host . $url . $hash . '?s=' . $size . '&r=' . $rating . '&d=';
            ?>
         <img class="avatar" src="<?php echo $avatar ?>">
         <?php $comments->author('', false); ?>
      </a>
      <span class="agent"><?php getOs($comments->agent); ?></span>
      <p class="msg"><?php $comments->content(); ?></p>   
      <div class="ctrl">
         <span><?php $comments->date('Y年n月j日'); ?></span>
         <span class="fo" data-name="<?php $comments->author('', false); ?>" onclick="javascript:alert('貌似还没做完这个功能QAQ~')">回应</span>
      </div>
   </div>
</li>

<?php } ?>
<div class="DS cmt">
<?php if($this->allow('comment')): ?>
   <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form" class="DS-input">
    <?php if($this->user->hasLogin()): ?>
<div class="DS-v">
  <div class="DS-visitor">
    <div class="DS-foRebox">
    </div>
    <div class="c">
      <div class="l">
        <span>
          <?php $this->user->screenName(); ?>
        </span>
      </div>
      <div class="r">
        <a target="_blank" class="DS-setBtn" href="<?php $this->options->profileUrl(); ?>">
          设置
        </a>
        <a rel="nofollow" href="<?php $this->options->logoutUrl(); ?>">
          登出
        </a>
      </div>
    </div>
  </div>
</div>
   <?php else: ?>
   <p><input type="text" name="author" title="昵称" class="text" placeholder="小明" required=""></p>
   <p><input type="email" name="mail" title="邮箱" class="text" placeholder="@gmail.com" required=""></p>
   <p><input type="url" name="url" title="网站" class="text" placeholder="http://"></p>
    <?php endif; ?>
   <p><textarea name="text" rows="5" title="评论正文" placeholder="在这里评论哟~" required=""></textarea></p>
   <p class="c">
      <button type="submit" class="l">评论</button>
      <smile class="DS-smile l"></smile>
   </p>
</form>
    <?php else: ?>
    <?php endif; ?>
<ul class="DS-cmt">
<?php $this->comments()->to($comments); ?>
<?php if ($comments->have()): ?>
<?php $comments->listComments(array('before'=>'' , 'after'=>'')); ?>
<?php endif; ?>
</ul>
</div>

<?php
/*
<div id="comments">
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()): ?>
   <h3><?php $this->commentsNum(_t('暂无评论'), _t('仅有一条评论'), _t('已有 %d 条评论')); ?></h3>

    <?php $comments->listComments(); ?>

    <?php $comments->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>

    <?php endif; ?>

    <?php if($this->allow('comment')): ?>
    <div id="<?php $this->respondId(); ?>" class="respond">
        <div class="cancel-comment-reply">
        <?php $comments->cancelReply(); ?>
        </div>

       <h3 id="response"><?php _e('添加新评论'); ?></h3>
       <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
            <?php if($this->user->hasLogin()): ?>
          <p><?php _e('登录身份: '); ?><a href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a></p>
            <?php else: ?>
          <p>
                <label for="author" class="required"><?php _e('称呼'); ?></label>
             <input type="text" name="author" id="author" class="text" value="<?php $this->remember('author'); ?>" required />
          </p>
          <p>
                <label for="mail"<?php if ($this->options->commentsRequireMail): ?> class="required"<?php endif; ?>><?php _e('Email'); ?></label>
             <input type="email" name="mail" id="mail" class="text" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
          </p>
          <p>
                <label for="url"<?php if ($this->options->commentsRequireURL): ?> class="required"<?php endif; ?>><?php _e('网站'); ?></label>
             <input type="url" name="url" id="url" class="text" placeholder="<?php _e('http://'); ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
          </p>
            <?php endif; ?>
          <p>
                <label for="textarea" class="required"><?php _e('内容'); ?></label>
                <textarea rows="8" cols="50" name="text" id="textarea" class="textarea" required ><?php $this->remember('text'); ?></textarea>
            </p>
          <p>
                <button type="submit" class="submit"><?php _e('提交评论'); ?></button>
            </p>
       </form>
    </div>
    <?php else: ?>
    <h3><?php _e('评论已关闭'); ?></h3>
    <?php endif; ?>
</div>
*/
?>

查看全部 2 个回答

推荐答案

0

已采纳

在form中增加一段这样的代码:

<?php $security = $this->widget('Widget_Security'); ?>
            <input type="hidden" name="_" value="<?php echo $security->getToken($this->request->getReferer())?>">

修改之后大概是这个样子:

      <p>
            <label for="textarea" class="required"><?php _e('内容'); ?></label>
            <textarea rows="8" cols="50" name="text" id="textarea" class="textarea" required ><?php $this->remember('text'); ?></textarea>
        </p>
      <p>
            <button type="submit" class="submit"><?php _e('提交评论'); ?></button>
        </p>
        <!-- 新增代码 -->
        <?php $security = $this->widget('Widget_Security'); ?>
            <input type="hidden" name="_" value="<?php echo $security->getToken($this->request->getReferer())?>">
            <!-- 新增 代码结束 -->
   </form>
</div>

更多内容,请移步 www.typechodev.com