Monday, July 16, 2012

Disqus on Blogger

Installing Disqus comments into your Blogger is fairly easy following official guide here (if you are using the new template system) or if you prefer classic templates like me you can follow universal code guide here. The problem is that Disqus is using full url to identify your discussion threads by default. You can use disqus_identifier to solve it like this:
<script type="text/javascript">
  var disqus_shortname = 'blobdot';
  var disqus_identifier = "<$BlogItemTitle$>";

  (function() {
    var dsq = document.createElement('script'); dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = 'http://' + disqus_shortname + '';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

This will make a unique identifier by using your post name like "Best vacation ever" instead of full url. Now to get the correct comment count you have to retrieve them with this new unique identifier. Put this where you have your Disqus comment link:
<a class="comment-link" href="<$BlogItemPermalinkUrl$>#disqus_thread" data-disqus-identifier="<$BlogItemTitle$>"></a>

This is not the best way to identify your posts since you can have several with the same name. This was the quickest solution for my blog.

Labels: , , , ,

comments powered by Disqus