Place blocks anywhere on the site

If you want to place blocks on a page or story or anywhere on your site , or on front page , here is a quick trick

Code for Recent Comments: Drupal 5


<?php
$block = module_invoke('comment', 'block', 'view', 1);
print $block['content'];
?>

Here is the code for Drupal 6

<?php
$block = (object) module_invoke(‘comment’, ‘block’, ‘view’, ‘1’);
print theme(‘block’,$block);
?>

Code for who’s online:

<?php
$block = module_invoke('user', 'block', 'view', 1);
print $block['content'];
?>

If you have event module installed you can show list of upcoming events

<?php
$block = module_invoke('event', 'block', 'view', 1);
print $block['content'];
?>

Display a custom block created by Admin :

<?php
$block = module_invoke('block', 'block', 'view', 1);
print $block['content'];
?>

In the code above the “1” indicates the first block. To display 2nd , 3rd, and subsequent user created blocks replace 1, with, 2, 3 etc respectively.


Here’s the ultimate trick
, you can display any block you want anywhere on your site. Goto Administer–> blocks–> There you will see link “configure besides each block , which looks like this

Leave a Reply

Your email address will not be published. Required fields are marked *