Share/Save

Place blocks anywhere on the site

admin's picture

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.

 #

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

 
 #

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.

 

User login

QT1

There are currently 0 users and 4 guests online.