Typecho Wiki
每一个作品都值得被记录

Typecho 评论增强插件 TeComment

Typecho维基君插件列表 • 4858次浏览 • 发布 2018-07-01 • 更新 2018-07-01 • 立即下载
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码
🛜自用大流量超低月租手机卡推荐榜单 #拒绝流量焦虑

插件简介:

Typecho 评论增强插件,可为 Typecho 评论增加评论工具栏、实现评论列表异步加载以及Ajax提交评论功能

1、安装插件

  • 下载插件后,确认插件文件夹名称为TeComment,
  • 上传插件文件夹TeComment至网站目录usr/plugins/
  • 进入后台,在导航 控制台 > 插件 页面,选择启用TeComment插件

2、使用插件

2.1、评论工具栏

安装好插件后,要想显示评论工具栏,需要修改当前所使用主题的comments.php文件:
在textarea标签后插入如下代码(可自行确定放置位置)

<?php TeComment_Plugin::showTool();?>

2.2、使用评论列表异步加载或Ajax提交评论功能前提

在开启评论列表异步加载或Ajax提交评论功能前,需要修改当前所使用主题的functions.php文件:

若functions.php文件中添加或替换threadedComments函数为

/**
 * 重写评论显示函数
 */
function threadedComments($comments, $options){
    $html = TeComment_Plugin::parseCommentHtml($comments, $options);
    
    $children = '';
    if ($comments->children) {
        ob_start();
        $comments->threadedComments();
        $children = ob_get_contents();
        ob_end_clean();
    }
    $html = str_replace('>{children}<','>'.$children.'<',$html);
    echo $html;
}

2.3、评论列表异步加载功能

要开启‘评论异步加载’功能,在插件设置页面启用‘评论异步加载’后,还需要修改当前所使用主题的comments.php文件:

<?php $this->comments()->to($comments); ?>
<?php if ($comments->have()): ?>
<?php $comments->listComments(); ?>
<?php $comments->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>
<?php endif; ?>

修改为

<?php if($this->options->plugin('TeComment')->commentAjaxLoad): ?>
    <div id="comment-ajax-list" data-cid="<?php $this->cid();?>" data-num="<?php $this->commentsNum();?>" data-comment-page="<?php echo $this->request->commentPage;?>"></div>
<?php else: ?>
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()): ?>
    <?php $comments->listComments(); ?>
    <?php $comments->pageNav('&laquo; 前一页', '后一页 &raquo;'); ?>
    <?php endif; ?>
<?php endif; ?>



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

修改为

<?php echo '<a id="cancel-comment-reply-link" href="' . $this->permalink . '#' . $this->respondId . '" rel="nofollow"' . ($this->request->filter('int')->replyTo ? '' : ' style="display:none"') . ' onclick="return TypechoComment.cancelReply();">'._t('取消回复').'</a>'; ?>

2.4、Ajax提交评论

要开启‘Ajax提交评论’功能,只需要在在插件设置页面启用‘Ajax提交评论’即可

此功能兼容系统默认的反垃圾保护功能

2.5、评论模板

为了实现评论列表异步加载和Ajax提交评论功能,插件引入了评论模板,默认的评论模板为:

<li id="{theId}" class="widget {commentClass}">
    <div class="comment-meta">
        <div class="comment-meta-avatar">{authorAvatar}</div>
        <div class="comment-meta-author">
            <strong>{beforeAuthor}<a href="{authorUrl}" rel="external nofollow" target="_blank">{authorName}</a>{afterAuthor}{commentStatus}</strong>
        </div>
        <div class="comment-meta-time">{beforeDate}{created}{afterDate}</div>
            <div class="comment-meta-reply">{replyLink}</div>
        </div>
    <div class="comment-content">{content}</div>
    <div class="comment-children">{children}</div>
</li>

可根据模板的需要自行设计评论模板,可用参数包括:

{theId} 评论锚点ID

{commentClass} 评论列表样式

{authorAvatar} 评论用户头像

{authorName} 评论用户名称

{authorUrl} 评论用户主页

{authorUrl} 评论用户邮箱

{created} 评论发布时间,时间格式为后台设置的格式

{replyLink}回复评论的链接

{content} 评论内容

{children} 子评论

先看效果图:

Typecho 评论增强插件 TeComment

js效果部分参考了张戈博客中的代码
工具栏中,表情的功能基本上是拷贝自羽中漫步的Smilies插件,可在后台设置使用的表情包

使用方法:

<?php TeComment_Plugin::showTool();?>

启用插件后,在comments.php文件的合适位置加上以上代码即可。

下载地址
本站免费下载所以请关闭浏览器广告屏蔽插件支持一下!
注册 登陆
  • 2018年07月01日
  • Typecho 评论增强插件 TeComment
  • 绛木子
  • 下载链接需要注册登录或者评论审核后方可阅读!
  • 广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,Typecho.Wiki所有文章均包含本声明。
    本文检索关键词:typecho
    厂商投放

    【腾讯云】🎉五一云上盛惠!云服务器99元/月续费同价!

    腾讯云五一劳动节海量产品 · 轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。快来腾讯云选购吧!

    广告
    添加新评论 »

    仅有一条评论 »

    1. 感谢分享