Skip to Content

Custom Drupal Theme Block Regions

I recently added Google AdSense ads to this site to see what the click-through-rate will be. I wanted to put a banner ad above the content section you are reading right now in addition to side blocks. Since I'm using the bluemarine theme, there was not a way to put blocks into the section above the main content, so I modified the bluemarine theme to make this happen.

It's very easy to add/change block regions in a theme. Here's the steps for modifying the bluemarine theme:

1) Copy the bluemarine directory (with all its files) to sites/all/themes and rename the directory, e.g. mybluemarine

2) Go to that new directory and rename the bluemarine.info file to match your directory name, e.g. mybluemarine.info

3) Add the regions to the .info file, e.g.

regions[header] = Header
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content_top] = Above content
regions[content_bottom] = Below content
regions[footer] = Footer

4) Modify the page.tpl.php file to match the regions from (3). In this case, the header, left, right, and footer regions are the same as before. I've added the content_top and content_bottom regions, so I will add them to the page template. e.g.

Before:

        <?php print $breadcrumb ?>
        <h2 class="title"><?php print $title ?></h2>
        <div class="tabs"><?php print $tabs ?></div>
        <?php if ($show_messages) { print $messages; } ?>
        <?php print $help ?>
        <?php print $content; ?>
        <?php print $feed_icons; ?>

After:

        <?php print $breadcrumb ?>
        <?php print $content_top ?>
        <h2 class="title"><?php print $title ?><h2>
        <div class="tabs"><?php print $tabs ?></div>
        <?php if ($show_messages) { print $messages; } ?>
        <?php print $help ?>
        <?php print $content; ?>
        <?php print $feed_icons; ?>
        <?php print $content_bottom ?>

5) Make sure to switch your site's theme over to your new theme on the admin/build/themes page.

The "content_top" and "content_bottom" matches the regions in the .info file. Very easy! Now you can ad any blocks you want above the content.

Tagged in:
ALL COMMENTS ARE MODERATED AND SPAM WILL BE DELETED SO SAVE YOUR TIME AND MINE AND ONLY LEAVE A COMMENT IF YOU ARE REALLY LEAVING A COMMENT AND NOT TRYING TO LINK OFF TO ANOTHER SITE FOR SOME GOOGLE LOVE.

Comments

header block problem

hi
i have to set a header block in my project, when i entered in to block module i set one header file and saved it but it doesnt display the top header file. am a new user with drupal if u help me then i can able to do this project hope u will sole this problem soon

Not sure I understand the

Not sure I understand the problem. I'm assuming that the header region shows up in your theme when you go to the /admin/build/block page. If so, make sure that it is in the page.tpl.php file(s) as well.

If the header region does exist, try moving an existing block that you know *works* into the header region. For example, the little drupal icon that shows up at the bottom of this website. If that shows up in your header region, then something is wrong with your block. If it doesn't, then something is wrong with your header region.

If you have added the header region yourself (correctly), try flushing your cache (particular your theme registry). Here's one of my articles on that: http://www.kristen.org/content/how-get-drupal-theme-change-show

Thanks

Your tip saved me hours!

Post new comment - ALL COMMENTS ARE MODERATED - SPAM WILL BE DELETED!

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Powered by Drupal, an open source content management system