Front page blocks for plain PHP themes

Last modified: January 1, 2008 - 21:27

I was able to add a front page block by editing the drupal.theme file in my plain PHP theme. This means if you are using a Chameleon clone (the one with the chameleon.theme file) all you have to do is add the new blocks reference to the yourtheme_regions() function, the block theme reference to the yourtheme_page function:

  // Get blocks before so that they can alter the header (JavaScript, Stylesheets etc.)
  $blocks_left = theme_blocks('left');
  $blocks_right = theme_blocks('right');
  $blocks_home_center = theme_blocks('home_center');

then add the following code where you want your block to appear.
  $output .= "\n<!-- begin content -->\n";

  if ( $show_blocks && !empty($blocks_home_center) && drupal_is_front_page() ){
    $output .= "<div id=\"home_center\" class=\"home-center\">$blocks_home_center</div>";
  }

As you can see I put mine just after the begin content marker. For left and right blocks the areas in the theme file are clearly marked.

If this is a center block, you may also need to add a line to common.css after .block

.block {
  width: 180px;
}
#block-block-11{
width: 100%;
}

You will need to publish the block or hover over the configure in admin blocks to get the block number

 
 

Drupal is a registered trademark of Dries Buytaert.