I have been trying to insert a custom region into my theme for several hours, but didn't have much success. The so called two step process seems quite simple:

1) add

function mytheme_regions() {

return array(
'content_top' => t('content top'),
);
}

into the template.php file and then insert some

print $content_top

into the page.tpl.php file. However, when I check the regions from the Admin panel, a new region called 'content top' is never added. I have read several forum posts on this and all of them seem to be following the same steps. Any help is much appreciated.

Comments

nevets’s picture

Well first off, which version of Drupal are you using?

Second the function mytheme_regions() suggests you are using Drupal 5, the functions needs to returns a list of all the possible regions (not just the new one) and 'mytheme' needs to be the name of the theme.

Lastly from the block admin page you would need to add blocks to the region.

hovhannisyan’s picture

Thanks for your answer,

That's a good insight, as it appears I was attempting to run code fragments for Drupal 6.2, while they were aimed for Drupal 5. I read in another post that the regions for later versions are defined like

regions[sub_header] = sub header

in the .info files, although the post was not specific what .info file needed to be updated. Could you let me know what file should be modified for Drupal 6?

yuriy.babenko’s picture

Add this to the .info file for your theme

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer

(Add your custom regions, too.)

With drupal 6.x you have to "rebuild" the "theme registry" whenever you make any changes to the .info file, so put this at the top of your template.php (again, in your theme's folder) while you're in development (should be removed for production):

drupal_rebuild_theme_registry();

---
Yuriy Babenko
www.yubastudios.com

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

hovhannisyan’s picture

Thank you very much for your help. It finally worked!

Here are a few things that were causing the problem.

First, I needed to update the [my theme].info file for the 6.2 version instead of the template.php. And a lot of posts on the forum, as well as a book by David Mercer were presenting the other option without actually specifying the differences between the versions. As you mentioned I needed to add something like this into [my theme].info file

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[custom_region_1] = custom region 1
regions[custom_region_2] = custom region 2
regions[custom_region_3] = custom region 3

However, it still did not work until I realized there was a caching problem; it did not let me see the newly added regions on the admin -> blocks panel, although all my caching options have been disabled there. I needed to go and manually clear the cache at
Administer >> Site configuration >> Performance -> Clear cached data

After those steps I could finally see the new regions on the Admin ... -> blocks section.
Hope this post will be helpful for others too.

solona’s picture

Oh thank you thank you thank you!! This is a very helpful post! You saved me from hours of hair-pulling.

OldAccount’s picture

Thanks for the cache tip, I was getting so frustrated trying to figure this out! Was restarting the server, etc. Seems like this should be a bug?

aangel’s picture

despite clearing the cache in every way imaginable, then changing the theme to something else then back again, my regions would not show up in the dropdowns on the block page.

The culprit was the administration theme. Without it also being set to the custom theme, the dropdowns won't be filled with the proper regions even though the administration theme should be just for administration.

I suppose this makes sense...

Beedge’s picture

Changing to admin theme did it for me too. This makes no sense to me at all!

jpowel25’s picture

This was exactly what was happening to me as well.

weber01’s picture

Hi,

I have a problem with my regions, I followed all the instructions, even cleared the cached using phpmyadmin, changed the permissions of .info to 777 on the server... and I just get either the custom regions, or the default ones, when my .info file contains all of them, I tried putting my custom regions above the others, then under, I changed the admin theme to my custom theme, I swiched themes several times...

What am I doing wrong, I cannot see where the problem is.

I am using Drupal 6 and modified version of Garland.

Ah I have also added the function to template.php as advised above. :(

weber01’s picture

Well, I don't really understand why but I changed the position of my stylesheet lines in .info, before they were after the regions, now I moved them to the bottom and I ordered them. Also I set the permissions of the file to 766 and it works now.

When I looked at the forum posts before, the position of the stylesheets[][all] lines did not seam to matter, so, I am surprised this has solved the problem.

grb’s picture

All the above was very helpfull and I did all, but it still didn't solve the problem for me.
Switching back to Garland theme, the regions are shown.
So I looked at the blocks table, and it appeared the data was incorrect for my theme.
I fixed it based on the values for Garland theme, then it worked.
Seems like the updates on the table are not going as should for my installation.
I am using 6.15.

interfaced’s picture

I had this same problem. I had to turn off the admin theme for it to recognize the regions. Hope this helps!

ercder’s picture

Thank you, this resolved my issue.

Geldora’s picture

Thanks a lot, it helps!!!

akberhussain’s picture

in the theme.info

add this line

regions[contenttop] = Content top
regions[contentbottom] = Content bottom
regions[contentfooter] = Content footer

in the page.tpl.php

add this line

if ($contenttop):

print $contenttop;

endif;

mgalalm’s picture

I could did this using drush

drush cc and choose the number represents the theme list