Mywebdunia's Blog

Archive for June 2010

Blocks are nothing but boxes of content, that are displayed in regions such as sidebar or footer on your page.

For creating a block go to Administer >> Block >> Add block, you will find a form fill the details of your block and save it.

Say for Example you have created a block with name Test Block with ID 1. Here’s how you use this code snippet to insert any block

Browse to Site Building >> Blocks >> List Browse over the “configure” link next to your block

This will reveal the following address line (in this example we are using a custom block with ID 1)

/admin/build/block/configure/block/1

the last two variables are the ones we’re interested in: /block/1

Now to place this custom block into a page, we need to just add these code into the PHP code snipped

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

Note that the middle two terms (‘block’, ‘view’) always stay the same. You’re simply updating the first and last term.

The first term can be a comment, user, event, block or module_name for displaying recent comments, online user, if you have event module installed you can show list of upcoming events or to display a custom block created by Administrator or any module to be displayed respectively.

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


Categories