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.

Tags: 

Comments

Condition Check for Custom Region Assigned Block

Hello,

I have written a post on by blog site for checking the condition for value of region at page.tpl.php. I am putting URL here, so if somebody comes here searching, can get help --

http://www.drupalconnect.in/condition-check-custom-region-assigned-block

Thanks,
RajeevK

How to add more items in the primary links

Hi,

Is there a way to word wrap the menu items in the orange bar. For e.g in the orange bar above there is a link BASIC SEO(Top 10). Can we wrap it such that Top 10 shows up in the line below.

I am using the blue marine theme as well and I have about 10 items to include under primary links. Since all of them are long titles, I am having trouble accomodating them.

Your input would be really helpful.

Thanks

Sorry for the delay!

Sorry for the delay... haven't been getting comment notifications.

You could use menu_attribute to add some CSS ids to your menu items and then CSS to wrap where you need to.

Thank you

oh thank you...i tried it on drupal forums

https://www.drupal.org/node/242107#comment-798428

but i was getting more confused, its so easy and step to step guide... :)

Thanks. Very clear and easy

Thanks. Very clear and easy to follow. I know what I'm doing now.

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!

I'm a Speaker at DrupalCon Portland