Wednesday, 08 April 2015 19:01

How to add Disqus (comment integration) into Joomla+K2

Before we begin, yes, K2 does have its own, built-in comment functionality.  And yes, there are plugins already built and available for this.  The reason I like this solution is twofold:

  1. K2's comment functionality, while has many useful features (Captcha anti-spam, email notifications, admin approval process), people seem to like using Disqus because it supports logins from multiple accounts (Disqus, Facebook, Google, Twitter).  K2's inbuilt commenting feature can be set up to allow comments from anonymous visitors, which opens up your site to comment spam.
  2. I don't like installing an entire plugin just to accomplish one little thing.  While I'm sure the plugin works, you have more customization / control when you handle the actual code.  This is similar to the plugins that allow you to add Google Analytics to your site - maybe it's just a pet peeve of mine - but I'd rather edit a (single, easy) file than install a new extension, which is a potential security risk.

Let's get started, shall we?  

Below are a few files you'll need.  

  • Add_to_template_index-dot-php.zip
    This file contains a code snippet that you'll need to add to your site template's "index.php" file.  This can sometimes be accomplished by going into Extensions -> Template Manager, and using one of the template parameters to inject the code (assuming your template has this feature).  Or, you can go into the actual template's index.php file using FTP and change it directly:  /your_site/templates/your_template/index.php
    In the code, you'll see a reference to a "forum shortname" which comes from your Disqus account; you'll need to change my text that says "CHANGE_THIS" to your actual shortname.
  • disqus-override.zip
    This will extract and give you a folder labelled "disqus" - it is a K2 template override, which means if you're using overrides properly, it will go here: /your_site/templates/your_template/html/com_k2/
    Otherwise, the standard location for K2 templates is here: /your_site/components/com_k2/templates
    The standard K2 template folder will be called "default" - I suggest adding the "disqus" folder alongside the default folder so that you can use the K2 category parameters to indicate which sections of your site use comments and which ones do not.

Inside the disqus (disqus-override.zip) folder, there are only two files that you need to pay attention to:

  • item.php (lines 98-106, and lines 691-703)
    In the code (line 691), you'll see a reference to a "forum shortname" which comes from your Disqus account; you'll need to change my text that says "CHANGE_THIS" to your actual shortname.
  • category_item.php (lines 122-124)
Last modified on Wednesday, 08 April 2015 19:38
Comments (2)
This comment was minimized by the moderator on the site

It's ironic that this site does not use disqus comments

Also you left 1 important thing. Apart from short name you must add the disqus identifier otherwise your sef and non-sef pages will show a different set of comments. By default disqus uses...

It's ironic that this site does not use disqus comments

Also you left 1 important thing. Apart from short name you must add the disqus identifier otherwise your sef and non-sef pages will show a different set of comments. By default disqus uses the url to store and fetch comments against. Specifying the disqus id as the k2 item id will overcome this.

More
Ashwin
This comment was minimized by the moderator on the site

Excellent points, thank you. I use sh404sef so the non-sef-page item should be a non-issue? And no, I am not using Disqus on my own site because I prefer to host all of my data.

Nate Covington
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Suggested Locations

Latest Comments

Got a similar email that seemed suspicious. Ignored it and they even followed up today.
My organization received one of these emails from "Linda," but uses https://www.bestprosintown.com/p...
Hi Nate, I got the same email template from the same email address today and found you through a ...
Just received one today (16 Aug 2022) from "Mailchimp". Thanks for sharing!
Thanks for posting this. I just got one today. I was 99% sure it was a scam, and your post confirmed...


Design & Development

Wordpress, Drupal, Joomla
New custom websites
Bespoke themes and extensions
Redesigns, upgrades, migrations

Web Design & Development


Optimization & SEO

Let us optimize and manage your overall online presence. We offer full service monthly SEO as well as one-time projects.  

Optimization Plans & Pricing


Maintenance, Patching

White glove monthly backups, security updates, maintenance and testing for your Wordpress, Drupal, or Joomla site.

Maintenance Plans & Pricing


Email Newsletter

Bring your web & marketing performance to the next level: monthly blog post roundup via email.  

Stay in Touch!