Hi, I just installed Drupal 7 after long absence from using Drupal (about 3-4 years ago). So my question is: how do you add a new block region on Drupal 7?

Right now there are only these on admin option:

Left Sidebar
Right Sidebar
Content
Header
Footer
Highlighted
Help

I'd like to add a new block region called "Navigation" to replace the location of $primary_nav and $secondary_nav for a dropdown menu (using Nice Menu module). What are the straightforward steps-by-steps codes to put on? I've searched through the amazon jungle of Drupal Documentation but with no luck.

Thanks in advance!

Comments

hollybeary’s picture

Open up your theme's .info file and you should see some regions like this:

regions[featured] = Featured
regions[content] = Content
regions[sidebar_first] = Sidebar first
regions[sidebar_second] = Sidebar second

to add a new region just type in a new one in that .info file. I'd be careful of replacing any though as there are several regions in D7 that are required.

Then you'll need to print out your new region in your page.tpl.php file which goes something like this now:

<?php if ($page['sidebar_first']): ?>
      <div id="sidebar-first" class="column sidebar"><div class="section">
        <?php print render($page['sidebar_first']); ?>
      </div></div> <!-- /.section, /#sidebar-first -->
    <?php endif; ?>

Don't forget to clear your cache or you won't see the new region. It really helps to poke around in some other D7 themes and see how they've done things also.

kilimanjaro’s picture

It works wonderfully! :)

alltooeasy’s picture

Thanks, a great little snippet.
Now wrestling with some triple wrapped columns that aren't playing nicely.

yyx’s picture

hello, i‘m learning the drupal. i tried but there is a problem in the project. if i dont add " if ($page['sidebar_first']): endif; " they work well, but when i add " if ($page['sidebar_first']): endif; ", there is no content displaying in my test website, could you help me?

JonnyJ-1’s picture

You have your "if" statement, now you need your "then" statement:


<?php
if ($page['sidebar_first']): //If there is content in sidebar_first
?>

<?php print render($page['sidebar_first']); ?> //Then render the sidebar

<?php
endif;
?>
bzsim’s picture

I just have to say that this new formatting erks me. I am a front-end person, so I finally got comfortable with doing things in 6 like adding new regions, digging in the PHP and doing some rearranging, etc, and now they had to go and change the way things work which makes it super difficult for someone like me and I know have to Google everything and re-learn how to do things in 7. I know, I know, I just have to adapt, but really it is frustrating and makes me just want to stick with 6.

hwi2’s picture

Bzsim, yes, I felt the same the same exact way when I saw the differences between 6 and 7. You don't have to adapt. Just download Drupal 6. It is still out there for the taking. LOL

But seriously, just remember, it's like anything else in Drupal, once you get the hang of Drupal 7, you will look back and laugh. We all have to get used to it.

Now, the REAL fun is waiting to see how Dries will drive us nuts with the Drupal 8 changes. LOL

Bruce

Lesliey’s picture

I rather enjoy coding, but this new system is just an inefficient time sucking mess.

mbarnhizer’s picture

Knew to Drupal and CMS as a primary type of website. I have spent my last couple of weeks tearing apart themes loading different ones and learning how they come together. For anybody in my shoes or would like a testing ground try Drupal Gardens which gives a look at a well defined functioning system to help with defining all the pages. For making changes to a live system where you have access to all of the files you have Web Matrix and Dev Desktop those two load on your computer and ride in the localhost. I found them very useful to learn with. Getting away from why I am posting, but those i see as useful tools.

When i view source of a system i see a heck of a lot. Trying to determine where i can remove a background or how to position them is a little foggy to say the least. Seeing in your post how you add a block and reading how some blocks are required brings me to these questions.

How do I know which blocks I can or cannot mess with?
Is their a way to control with pixel accuracy the position of the contents of block?

My thinking is telling me that the use of tables and other css options is how to position the content within a block? Like the Header block. To have title, slogan, and rollover image I would place my css for all of it inside the block? Am I close, lost, on a trail to nowhere, or....??

Another one is how can I have my login and password fields horizontally placed in the upper right corner?

Positioning...???

whitelilac1212’s picture

hi, thanks for the tips it really works :D what about 2 left and right side bar? the theme i'm using has its left and right sidebar already but i want to create new left sidebar and right sidebar on top of the existing ones (it'll look like 2x2 table). can i do that?

athulya.baburaj’s picture

You resolved it? If so give me the solution.

Nipendra’s picture

Thanks hollybeary for such a nice and easy code! works me too.