Displaying Comment Count Links

You can display a count of the number of comments next to each article in your website with Commento’s count.js feature. To do this, simply include the following snippet in your HTML:

  1. <script src="https://cdn.commento.io/js/count.js"></script>

On pages where you want to display comment counts, append a #commento to the end of the href attribute of links should display the number of comments. Commento will automatically look for such links and fill them with the number of comments. For example, consider the following link.

  1. <a href="https://example.com/foo#commento"></a>

When the count.js snippet is included, Commento would automatically search for all such links ending with #commento and fill the inner text with the number of comments, like so:

  1. <a href="https://example.com/foo#commento">12 comments</a>

Configuration settings

Optional

data-page-id

When this attribute is set on the <a> tag, its value will be used as the identifier when fetching the number of comments. Must be identical to the data-page-id mentioned in the frontend configuration page.


Optional

data-custom-text

When this attribute is set on the <script> tag, its value will be evaluated using JavaScript’s eval function. The return value will be called to set a custom text. For example, consider the example snippet below.

  1. <a href="https://example.com/foo#commento"></a>
  1. <script>
  2. window.commentCustomText = function(count) {
  3. if(count === 0) {
  4. return "No comments";
  5. } else if (count === 1) {
  6. return "1 comment";
  7. } else {
  8. return count + " comments";
  9. }
  10. }
  11. </script>
  12. <script src="https://cdn.commento.io/js/count.js" data-custom-text="window.commentoCustomText"></script>