Add "first" and "last" classes on blocks
- Posted By:chup@drupal.org
- Category:Blocks, Misc
- Type:PHP
- Views:670
Sometimes, the first or last block in a region needs to be styled different than the rest. This solution do this in simple way for Drupal 6.
(originaly code from Remi@drupal.org: http://drupal.org/node/293188#comment-1282186)
Snippet:
You need to change themename to your themplate name.
Login/Register to Comment this Snippet<?php
function themename_preprocess_block(&$vars, $hook)
{
static $counts;
if(!isset($counts)) $counts = array();
$region = $vars['block']->region;
if(!isset($counts[$region])) $counts[$region] = count(block_list($region));
$count = $counts[$region];
$extremity = '';
if($vars['id'] == 1) $extremity = 'first';
if($vars['id'] == $count) $extremity = 'last';
$vars['classes'] .= $extremity != '' ? ' ' . $extremity : '';
}
?>You need to change themename to your themplate name.