Gareth Redfern developer, cyclist & coffee lover

Adding A Comment Count With Disqus & Statamic

Posted by Gareth Redfern
Category: statamic

The set up is really quite straightforward and the Disqus help page provides the script example required. I used the following script which I added to a disqus.js file in my theme’s js directory.

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'example'; // required: replace example with your forum shortname


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

You will need to change the username to your own but other than that the script is ready to go. The final part is just appending #disqus_thread to your post link where you would like the comments to display.

<a href="{{ url }}#disqus_thread">Read More</a>

I created a read more link in the footer of the article listing so that if JavaScript was disabled for any reason then the script will fail gracefully and the link will still be useful. When JavaScript is enabled the read more text will be replaced with the comment and reaction count.