javascripthtmlhandlebars.jsdisqusghost

Ghost 1.0 Disqus Comment Count Not Reflecting the Post Comments


I recently updated my Ghost version from 0.11.11 to 1.12.0

I also added a PAGE_IDENTIFIER as per the Disqus - JavaScript configuration variables

The comment count on the index page is not reflecting the post comments.

This link displays the main page comment counts for each post, in particular the post for Firefox is 0 comments

This link displays the Firefox post with Disqus comment count of 4.

The following is my current script for comments

<script type="text/javascript">
  /* * * DON'T EDIT BELOW THIS LINE * * */
  (function () {
    var s = document.createElement('script');
    s.async = true;
    s.type = 'text/javascript';
    s.src = '//' + disqus.shortname + '.disqus.com/count.js';
    (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
  }());
</script>

I am using the following to create the comment count link

<i class="fa fa-comment-o"></i> <a href="{{url absolute="true"}}#disqus_thread" data-disqus-identifier="{{comment_id}}">Comments</a>

The post comment script is as follows

<script type="text/javascript">

  var disqus_config = function () {
    this.page.url = '{{url absolute="true"}}';
    this.page.identifier = '{{comment_id}}';
    this.page.title = '{{title}}';
  };

  /* * * DON'T EDIT BELOW THIS LINE * * */
  (function () {
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus.shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>

Questions

I have recently updated the URL links using the mapper but will this pickup the new page.identifier?

If not, what steps can I take to fix the comment count?

Investigation

1. The count.js file is indeed loaded as the link text is being replaced after load.

2. I found that an object is created when the Disqus count script is loaded called DISQUSWIDGETS. The DISQUSWIDGETS.forum field is undefined.

3. jnowland on GitHub Gist has deconstructed the count.js file and it seems the DISQUSWIDGETS.forum has to be defined in order to set the correct details to retrieve the count.


Solution

  • As per jnowland's count.js file on GitHub Gist, the disqus_shortname must be declared and defined before executing the Disqus comment count script.

    This will set the DISQUSWIDGETS.forum field correctly.

    <script type="text/javascript">
      var disqus_shortname = "MY_SHORTNAME"; // Replace MY_SHORTNAME with your DISQUS shortname.
    
      /* * * DON'T EDIT BELOW THIS LINE * * */
      (function () {
        var s = document.createElement('script');
        s.async = true;
        s.type = 'text/javascript';
        s.src = '//' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
      }());
    </script>