This shows you how to display the number of Disqus comments for you static blog posts on the home page or any other article extracts/list page.
Get the count.js script
Insert the following script at the bottom of your page:
<script id="dsq-count-scr" src="//SHORTNAME.disqus.com/count.js" async></script> |
Where SHORTNAME
is your disqus Shortname/ID. It is different from the usual embed.js
file.
Set up your links
Simply add #disqus_thread
at the end of each URL in each <a>
tag that needs to display the list of comments. It is important that the URL before the anchor corresponds to a URL with comments ON.
Example:
<a href="http://codeblocq.com/post1.html#disqus_thread"># COMMENTS</a> |
In the markup above, the # COMMENTS
text will be replaced by the number of comments (0 comments, 1 comment, n comments..)
You can specify the strings to be used in your admin page.
Hexo example
Here is how I do it with Hexo (ejs template) but it can easily be adapted to anything else.
<!-- Disqus Comments --> |
This will generate the correct script tag at the end of the <body>
:
embed.js
if it’s a ‘details’ pagecount.js
if it’s the home page
Then use the following code to declare the link
<a href="<%- item.permalink %>#disqus_thread"></a> |
You can check out Hexo’s default theme (at the time of writing) for more information.