We needed to have a newsflash announcement at the top of certain pages on a site. Here is a quick way of doing this with minimal theme code.

In order to do this, we decided to use the new "regions" feature for Drupal 4.7 blocks.

To do this, edit the template.php file in your theme directory. Add the following hook to it:

function yourtheme_regions() {
return array(
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content_top' => t('content top'),
'content' => t('content'),
'header' => t('header'),
'footer' => t('footer'),
);
}

Then, in page.tpl.php, add this snippet above the breadcrumbs (or anywhere else you want).

<?php if ($content_top) : ?>
<div align="center"><?php print $content_top ?></div>
<?php endif; ?>

You now have a region called 'content top' in the administer -> blocks page. In it you can put any text you want, and restrict visibility to certain areas of the site using the standard waya of doing so for blocks.

One can get more creative and write a custom module that would publish blocks on certain dates, and such ...

Comments

Tue, 2006/08/08 - 04:08

"edit the template.php file in your theme directory"

Can't find that file anywhere. Where is it?

Not anywhere in 4.7 or the 4 themes that comes with it.

Tue, 2006/12/05 - 09:37

I'm in search for some good documentation on the web about drupal themes "how-to" and i have found your website interresting :

You have written in your example :

function yourtheme_regions() {
  return array(
    'left'        => t('left sidebar'),
    'right'       => t('right sidebar'),
    'content_top' => t('content top'),
    'content'     => t('content'),
    'header'      => t('header'),
    'footer'      => t('footer'),
  );
}

I'm not sure if i'm right but there is no 'comma' at the end of an array (I'm not a PHP expert like you are...)

function yourtheme_regions() {
  return array(
    'left'        => t('left sidebar'),
    'right'       => t('right sidebar'),
    'content_top' => t('content top'),
    'content'     => t('content'),
    'header'      => t('header'),
    'footer'      => t('footer') // There is NO comma at the end of the last region defined because we are closing the array //
  );
}

Tue, 2006/12/05 - 09:40

Actually PHP allows both with and without an end comma.

It is very convenient to be able to add lines after the last one, or rearrange them without the need to remember to remove the comma at the end.
--
2bits -- Drupal and Backdrop CMS consulting

Tue, 2011/01/04 - 02:27

i can't find any region called 'content top' in the administer -> blocks page. after applying ur code in both the files. Plz help

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting