获取多说评论数并集成到Typecho

插件开发及发布

版主: woniou

回复
lovefree13
帖子: 1
注册时间: 2015年 3月 28日 20:09

获取多说评论数并集成到Typecho

帖子 lovefree13 »

使用了多说的社会化评论系统,但获取评论数和显示评论数是个小问题,自己写了几行代码,用于在Typecho系统中,详情移步http://blog.xuyangjie.cn/toss/17.html
感谢支持
头像
ClayMore
帖子: 2481
注册时间: 2007年 11月 29日 02:55
来自: Sleeping Forest
联系:

Re: 获取多说评论数并集成到Typecho

帖子 ClayMore »

为什么使用多说评论系统
  因为想尽量减轻服务器压力,但也有人说多说加载慢。。个人感觉多说挺好用的,省去了好多麻烦。

多说的缺点
  也不知道Typecho有木有类似的插件,反正我没找,自己就做了,但还不是插件,只是写了一个function来调用多说的“获取文章评论数”公开API,并集成到Typecho,多说官方也有,但文档写的不清晰,糊里糊涂的(其实是我不怎么懂JS罢了,O(∩_∩)O~)

PHP获取评论数
  在当前主题文件夹下新建一个PHP文件,getDuoshuoComments.php,代码如下

代码: 全选

<?php

/**
* 获取文章多说评论数
*/
function getDuoshuoComments($threads){
    $url = 'http://api.duoshuo.com/threads/counts.json?short_name=xuyangjie&threads=' . $threads;
    $jsonComm = file_get_contents($url);
    $arrayComm = json_decode($jsonComm, TRUE);
    $counts = $arrayComm['response'][$threads]['comments'];
    if(!is_int($counts)){
        return 0;
    }
    return $counts;
}

  这里需要改的是short_name=xuyangjie,其中xuyangjie替换为你在多说创建二级域名。

  然后在需要显示评论数的地方添加<?php echo getDuoshuoComments($this->cid); ?>,就行了。当然你需要在显示评论数的文件添加include('getDuoshuoComments.php');,嫌麻烦的话,可以把getDuoshuoComments函数,写在header.php内。

  目前已知,可以在index.php,post.php,page.php三个页面添加并能正常显示,演示可见本小站。



__________________
阿里百秀Alibaixiu主题 v5.6 For Typecho http://xiu.160.me/
wwwdsd
帖子: 262
注册时间: 2009年 6月 13日 23:06
联系:

Re: 获取多说评论数并集成到Typecho

帖子 wwwdsd »

不用多说的路过
hopeknow
帖子: 1
注册时间: 2016年 2月 4日 15:58

Re: 获取多说评论数并集成到Typecho

帖子 hopeknow »

非常感谢!
拾叁同学
帖子: 15
注册时间: 2016年 8月 10日 01:03

Re: 获取多说评论数并集成到Typecho

帖子 拾叁同学 »

<div class="index-post-button index-post-comments">
<a href="<?php $this->permalink() ?>#comments"><?php $this->commentsNum(_t(' 没有评论 '), _t(' 1 条评论 '), _t(' %d 条评论 ')); ?></a>
</div>

请问楼主,这是我模板的index.php需要获取文章数的地方,请问要怎么修改才能显示多说的评论数呢
头像
yufan
帖子: 22
注册时间: 2016年 4月 16日 14:00
来自: http://yufanboke.top/
联系:

Re: 获取多说评论数并集成到Typecho

帖子 yufan »

拾叁同学 写了:<div class="index-post-button index-post-comments">
<a href="<?php $this->permalink() ?>#comments"><?php $this->commentsNum(_t(' 没有评论 '), _t(' 1 条评论 '), _t(' %d 条评论 ')); ?></a>
</div>

请问楼主,这是我模板的index.php需要获取文章数的地方,请问要怎么修改才能显示多说的评论数呢


这个方法早就不行了,我的代码给你参考

代码: 全选

<span class="comments"><a href="<?php $this->permalink() ?>#comments"><span class="ds-thread-count" data-thread-key="<?php echo $this->cid;?>" data-count-type="comments"><?php _e('评论')?></span></a></span>
回复