我一定是瞎了眼,但我一生都找不到让论文评论计数工作的完整说明。
我只想显示注释计数。
我已经选中了“在页脚中输出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>
最合适的回答,由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.\'">\';
}