Disqus Comments in a block
interestingaftermath - September 18, 2009 - 01:33
| Project: | Disqus |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Is there a way to move the disqus block out $content so that I could position it below the node's main theme section?
I notice this in the disqus.module code:
$node->content['disqus'] = array(
'#value' => $disqus,
'#weight' => 10,I am wondering if that could be altered somehow? Any tips would be appreciated. Thanks!

#1
This feature went into the Drupal 6 branch. It allowed the comments to be displayed in a block so you could move them anywhere you wanted. The patch wasn't back ported though since it was a large design change. If you want to have a look at disqus_block() in disqus.module, you'll see how it works.
I'm not opposed to any patches ;-) . Would love for it to be in the Drupal 5 branch, just haven't had the availability to back port it.... Any help is welcome.
#2
That's too bad. I don't have the ability to back port the module myself and it doesn't look like anyone will be coming along anytime soon to do so. Looks like my client will be stuck with Drupal comments :(
#3
I would be willing to donate for a patch of this feature for 5.0.
#4
I found this in another thread. Going to try it tonight!
I too didn't want the Disqus comment injected straight into the body. Instead, I'd rather have control over where they appeared by using my theme. I currently use Drupal 5.x, so these instructions maybe a little different for 6.x, but I've managed to figure out how to do this.
Line 76-79 in disqus.module currently has this:
$node->content['disqus'] = array('#value' => $disqus,
'#weight' => 10,
);
As jluster said above, this injects the Disqus code into the body with a weight of 10. If you're fine having the node links below the comments, you can modify the weight value to how you'd like it. Otherwise, change the code to this:
$node->disqus_comments = $disqus;This creates a variable when the node is viewed called $disqus_comments that you can place anywhere in your node.tpl.php
Someone else can chime in and tell you if the code is any different for Drupal 6.x, but this is the Drupal 5.x solution. Thanks!
#5
The Drupal 6 version is much nicer as it sticks it in $node->disqus during "load":
<?php
function disqus_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'load':
// See if Disqus is active on this node.
$types = variable_get('disqus_nodetypes', array());
if (!empty($types[$node->type])) {
// Check which Disqus domain to use.
$domain = variable_get('disqus_domain', '');
if (!empty($domain)) {
// Save the data to the node object.
$node->disqus = array('domain' => $domain);
// Build the absolute URL without the alias for the disqus_url flag.
$node->disqus['url'] = url("node/$node->nid", array(
'alias' => TRUE,
'absolute' => TRUE,
));
// Build the message excerpt.
$message = nl2br($node->teaser);
$message = str_replace("\r", ' ', $message);
$message = str_replace("\n", ' ', $message);
$message = strip_tags($message);
$node->disqus['message'] = check_plain($message);
// Build the title.
$node->disqus['title'] = check_plain($node->title);
// Provide the identifier.
$node->disqus['identifier'] = 'node/' . $node->nid;
// Inject the script.
if ($developer = variable_get('disqus_developer', FALSE)) {
$node->disqus['developer'] = $developer;
}
}
}
break;
case 'view':
// See if we are to display Disqus in the current context.
if (!$a3 && $a4 && isset($node->disqus)) {
if (user_access('view disqus comments') && variable_get('disqus_location', 'content_area') == 'content_area') {
// Inject the comments into the node content area.
$node->content['disqus'] = array(
'#value' => theme('disqus_comments', $node->disqus),
'#weight' => variable_get('disqus_weight', 50),
);
}
}
break;
}
}
?>
The solution should be very similar in the Drupal 5 version. Note that the
variable_get('disqus_location', 'content_area')is where you have the ability to set it as a block ;-) .#6
I was able to do the quick tweak I mentioned above and it worked just perfectly. I have disqus running on my site and the client is happy: e.g. http://davianletter.com/blog/2009/9/28/grains-fx-and-metal
#7
Nicely done, it looks great! If you stick up a patch or some code or something, I'd love to have a look.
#8
I backported what was in Drupal 6: http://drupal.org/cvs?commit=276868
#9
Automatically closed -- issue fixed for 2 weeks with no activity.