Add Regions to your Frontpage

Last modified: August 25, 2009 - 02:43

For Drupal 6.x, please see the handbook page Assigning content to regions.

Note that this is for use with PHPTemplate themes (the default theme engine in Drupal.) There is a page for Plain PHP themes to do something similar.

In this example we have a custom theme, called 'mytheme', and we are going to add three new regions to the frontpage. We will call them frontpage top, frontpage center and frontpage bottom.

Replace all occurrences of 'mytheme' with the name of your custom theme.

  1. Inside of themes/mytheme/template.php (create the file if it doesn't exist), add the following:
    <?php
    /** Define the regions **/
    function mytheme_regions() {
      return array(
           
    'left' => t('left sidebar'),
           
    'right' => t('right sidebar'),
           
    'content' => t('content'),
           
    'header' => t('header'),
           
    'footer' => t('footer'),
           
    'frontpage_top' => t('frontpage top'),
           
    'frontpage_center' => t('frontpage center'),
           
    'frontpage_bottom' => t('frontpage bottom'),
       );
    }
    ?>
  2. Now that the regions are defined, go to page.tpl.php (within your themes/mytheme folder).
    Place the following code where you would like to display the appropriate regions:
        <?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
        <div id="frontpage_top" class="frontpage">
          <?php print $frontpage_top ?>
        </div>
        <?php endif; ?>
  3. Repeat this procedure for all three frontpage regions. You can combine two regions within one if() statement to improve performance.
  4. To add blocks to these new regions, simply go to
    Administer > Site Building > Blocks

Now with some more HTML (tables) or CSS, you can place these regions anywhere on your frontpage, make them look nicer, etc.

If you do not want the default content to print on the frontpage, you should surround the <?php print $content ?> with an if (!$is_front).

Visit the blocks repository for nice blocks, or create them with views so that you can put them on your frontpage.

 
 

Drupal is a registered trademark of Dries Buytaert.