如何添加Disqus评论计数

时间:2011-02-27 作者:EddyR

我一定是瞎了眼,但我一生都找不到让论文评论计数工作的完整说明。

我只想显示注释计数。

我已经选中了“在页脚中输出JavaScript”选项。我有自定义循环,但我不知道应该在其中添加什么来激活评论计数。

我的循环。php文件是:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( comments_open() ) : ?>
        <a href="<?php echo get_permalink($post->ID); ?>#disqus_thread" class="post-disqus">
           <span class="dsq-postid"></span>
           <?php echo $post->comment_count; ?>
        </a>
    <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Discus的页脚javascript代码为:

<script type="text/javascript">
    // <![CDATA[
        var disqus_shortname = \'mysite\';
        var disqus_domain = \'disqus.com\';
        (function () {
            var nodes = document.getElementsByTagName(\'span\');
            for (var i = 0, url; i < nodes.length; i++) {
                if (nodes[i].className.indexOf(\'dsq-postid\') != -1) {
                    nodes[i].parentNode.setAttribute(\'data-disqus-identifier\', nodes[i].getAttribute(\'rel\'));
                    url = nodes[i].parentNode.href.split(\'#\', 1);
                    if (url.length == 1) url = url[0];
                    else url = url[1]
                    nodes[i].parentNode.href = url + \'#disqus_thread\';
                }
            }
            var s = document.createElement(\'script\'); s.async = true;
            s.type = \'text/javascript\';
            s.src = \'http://\' + disqus_domain + \'/forums/\' + disqus_shortname + \'/count.js\';
            (document.getElementsByTagName(\'HEAD\')[0] || document.getElementsByTagName(\'BODY\')[0]).appendChild(s);
        }());
    //]]>
</script>

2 个回复
最合适的回答,由SO网友:Marcin 整理而成

我在循环中显示注释数量时也有同样的问题。

我通过关闭文件中的两个过滤器来解决这个问题。第1124行的php:

<?php
#add_filter(\'comments_number\', \'dsq_comments_text\');
#add_filter(\'get_comments_number\', \'dsq_comments_number\');
我已经用disqs元素添加到我的模板span中:

<?php
if ( function_exists( \'dsq_identifier_for_post\' ) ) {
    global $post;
    echo  \'<span class="\'.$css_class.\' dsq-postid" rel="\'.htmlspecialchars(dsq_identifier_for_post($post)).\'">\';
} else {
    echo \'<span class="\'.$css_class.\'">\';
}

结束

相关推荐

WordPress 3.1和Disqus引发警告:帖子列表中出现Number_Format()错误

升级到WordPress 3.1后,Posts列表中每个帖子的评论计数现在显示PHP错误Warning: number_format() expects parameter 1 to be double, string given in /wp-includes/functions.php on line 155. 这个问题肯定与Discus comments插件有关,我怀疑它操纵了评论计数。我了解了如何通过编辑WP核心文件/WP admin/includes/class WP list表来修复此错误。p