Skip to main content

Drupal Themes

Our feature packed Drupal themes combine beautiful design with over 70 optional settings, our easy to use administration theme and all backed by our no fuss money back guarantee.

Drupal Design

Blow away the competition with our full service graphic design services. We focus on audience demands & brand identity to set the tone of your internet business strategies.

Drupal Designers and Themers Community

Join the first crowd sourced premium Drupal theme service. Become a rockstar designer or themer, share the profits and get exposure to a half million Drupal users.

How to add a sidebar-top region in Genesis

Post to Twitter
Screen shot showing sidebar top region

The Genesis starter theme for Drupal supports 3 different layouts including both sidebars on either the left or right of the main content. In this configuration it can be useful to have a sidebar-top region that spans the width of both sidebars, but sits on top of them. This tutorial shows you how to do this in Genesis.

An example of when you might want to do this would be to display a fixed height banner or contextual ads. Its not good for content that will change in height as it could overflow the div—while the fixed height limitation could be overcome, this tutorial is meant for beginners and is a simple strait forward explanation of how to add new regions in Drupal and how to position the new sidebar-top region using CSS.

Overview

  1. Add a new region to your subthemes .info file.
  2. Print the new region in page.tpl.php.
  3. Add CSS to position the new region correctly.

For the purposes of this tutorial I am using the genesis-2c layout, which places both sidebars on the right. You will need to make adjustments if you have altered the default width of the sidebars (default is 240px).

1. Add a new region

Open up your subthemes .info file and add the new region. You can call it whatever you want and in the example below I have called it sidebar_top

Note: after you have saved the info file you need to clear the theme registry so the new region will show up on the blocks page. By far the easiest way to do this is by using the Admin Menu module, which has a link to do this included under the Drupal links (the Drupalicon on the left). Otherwise go to Performance settings and clear cache data.

;----------// Regions

  ; You can define new regions here.

  regions[leaderboard]        = Leaderboard
  regions[header]             = Header Blocks
  regions[secondary_content]  = Secondary Content
  regions[content_top]        = Content top
  regions[content]            = Main Content
  regions[content_bottom]     = Content bottom
  regions[tertiary_content]   = Tertiary Content
  regions[sidebar_top]        = Sidebar Top ; Our new region
  regions[left]               = Sidebar Left
  regions[right]              = Sidebar Right
  regions[footer]             = Footer

2. Print the new region

Now in page.tpl.php we need to print the new region. The easy way is to just copy/paste one of the existing sidebars and change the variable name and add a new id, or just copy and paste the new sidebar_top code in the snippet shown below. Note that I have used id="sidebar-top".

Place the new region above the other sidebars. It should look like the following code snippet:

      <?php if ($sidebar_top): ?>
        <div id="sidebar-top" class="section sidebar region"><div class="sidebar-inner">
          <?php print $sidebar_top; ?>
        </div></div> <!-- /sidebar-top -->
      <?php endif; ?>
     
      <?php if ($left): ?>
        <div id="sidebar-left" class="section sidebar region"><div class="sidebar-inner">
          <?php print $left; ?>
        </div></div> <!-- /sidebar-left -->
      <?php endif; ?>

      <?php if ($right): ?>
        <div id="sidebar-right" class="section sidebar region"><div class="sidebar-inner">
          <?php print $right; ?>
        </div></div> <!-- /sidebar-right -->
      <?php endif; ?>

3. Add CSS to position everything

So now we have to position the new sidebar-top region so it displays correctly.

  1. First we float it left.
  2. Then we need to give it some negative margin-left to pull it into position.
  3. We need to set a height on it.
  4. Finally we need to add margin-top to the other sidebars so they don’t overlap the new sidebar top.

The margin top for the left and right sidebars needs to be more than the height of sidebar-top. For those of you who know Zen and how it positions the primary navigation, this is pretty much the same sort of idea.

Heres the CSS - the screenshots below show the CSS and regions using Firebug. Place the CSS in page.css with the other sidebar styles. You will notice I have added 20px to the margin-top value so there is a horizontal gutter.

#sidebar-top {
  background: #EEE; /* background color for dev only */
  float:left;
  height:240px; /* set a height on the new region */
  margin-left:-500px; /* use negative margin to pull the sidebar-top into position */
  width:480px; /* set a width equal to left + right sidebar widths */
}

#sidebar-left,
#sidebar-right {
  margin-top: 260px; /* use margin top to push the left and right sidebars down */
}

Screen shot showing firebug and the new sidebar-top region CSS
Screen shot showing firebug with margin-top added to the left and right sidebars

Comments

#1 Fixed height

Great tut!

Is overcoming fixed height limitation a complicated issue?

Can it be solved with CSS-only means?

#2 ...

I was thinking more of a jQuery solution to grab the height of the sidebar-top and set the margin-top on the other sidebars.

#3 I see. Well, that’s beyond my

I see. Well, that’s beyond my skills, but thanks anyway

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h2> <h3> <h4> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Adds typographic refinements.

More information about formatting options