How to add Disqus comment count

I must be blind but I can’t find for the life of me the full instructions for getting Disqus comment count to work.

All I want displayed is just the comment count number.

Read More

I’ve checked the “Output JavaScript in footer” option. I have custom loops but I have no idea what I supposed to put in them to activate the comment count.

My loop.php file is:

<?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; ?>

Disqus’s footer javascript code is:

<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>

Related posts

Leave a Reply

2 comments

  1. I have the same problem with displaying number of comments in the loop.

    I solve this by turn off two filters in file plugins/disqus/disqus.php at line 1124:

    <?php
    #add_filter('comments_number', 'dsq_comments_text');
    #add_filter('get_comments_number', 'dsq_comments_number');
    

    And I have added to my template span with disqus elements:

    <?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.'">';
    }