Place blocks anywhere on the site

admin's picture
in

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:


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

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.


Comments

thanks

Thanks you for useful information. I find it for a long time.
______
download movies

bera | Sat, 2008-05-10 18:27

's points

Points are visible to logged in users only

descriptionvalue
Members2246
Posts217
Comments112
Reads today
Reads all time
Hits today0