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 Drupal 7

<?php
$block = module_invoke('MODULENAME', 'block_view', 'DELTA');
print render($block);
?>

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

http://www.mydrupal.com/admin/block/configure/book/0

Notice last two parameters book & "0", you can replace this

in the module_invoke function, replace above parameters as

module_invoke('book', 'block', 'view', 0);

So now you can find out any block details and display it on your site anywhere you please.

How-To: 

Comments

Hi there,

We have an intranet here with drupal and other apps. I would like to be able to provide a front page with informations from various apps.

For Drupal : I have created a bloc view. I would like to be able to access this block from outside drupal.