You are hereHowTo: Integrate Disqus with Drupal
HowTo: Integrate Disqus with Drupal
When I added disqus to seanreiser.com I thought it was simple, but one of my tweeps asked for a howto so maybe it wasn't . Also I seem to have had a few hits on from google searching on "disqus drupal". So for the curious here's are the steps I followed.
Caveats:
- These directions are for Drupal 5. I suspect it will also work on other versions but have done no testing. A few folks have reported success using the following directions against Drupal 6.x.
- These directions are not warranted in anyway if they break your blog, delete your content, make you blind or steal your girlfriend I am not responsible. Please remember to do the proper due diligence before implementing any code.
- I realize that it would be elegant to create a Disqus module, but don't have the time right now to code it. If someone does, I have some ideas of some neat functionality, reach out to me.
- All that said, this should work.
In all honestly I've done this twice, once the wrong way, and once the proper way.
Here is the Quicker, but Wrong Way
- Go to disqus.com and sign up for an account
- Add your website and select the 'java code snippet'
- Paste both the HTML and JavaScript into the node.tpl.php in your current theme after the content section of the code. (I'd post it here, but every theme's node.tpl.php is different)
Here is Slightly More Complex, but Correct Way
- Go to disqus.com and sign up for an account
- Add your website and select the 'java code snippet'
- Goto Administer / Site building / Blocks / Add New Block
- Set the block description to 'Disqus'
- Paste the HTML and JavaScript Code into the block body
- Select "Full HTML" as Input Format
- Hit Save
- Goto Administer / Site building / Blocks / List
- Scroll down to the 'Disqus' block you just added and select configure
- Scroll down "Page specific visibility settings"
- Select "Show if the following PHP code returns TRUE (PHP-mode, experts only)."
-
In the box labeled "Pages" Paste the following:
- <?php
$match = FALSE;
$types = array('story' => 1, 'page' => 1, 'blog' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}
return $match;
?>
- <?php
- $types is the array of node types where you want comments turned on, add or delete as needed. I don't have comments on my activity stream
- Hit Save.
- Goto Administer / Site building / Blocks / List
- Scroll down to the 'Disqus' block you just added and select content from the dropdown.
- Goto Administer / Site building / Modules
- Scroll down to the comments modules and disable it.
The major advantage to the proper way is that the comments persist if you change themes.
You may also want to add your rss feed from disqus to your news aggregator and add the block to your sidebar.
Poof you're done. Good Luck!
Share and Enjoy!
/edit: Forgot to mention that you should disable the comment module.
/edit2: added enabling the block, ver 6.2 compatibility and some minor spelling errors, and the blog node type.
/edit3: I'm dropping disqus for now. The reasons are outlined here. I really like disqus and once they add comment importing I'll be back, but for today it's getting in the way of my grand design.
/edit4 I have reenabled Disqus. See this for more information
/edit5 Rob Loach has created a Disqus Module for Drupal 6 here
I'm still fairly new to Drupal, never used the PHP code returns TRUE box before and I think I now realize the power it can have. Great tutorial, thanks!