Return to Snippet

Revision: 18284
at September 26, 2009 07:27 by Fake


Initial Code
<?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.

Initial URL
http://drupal.org/node/293188

Initial Description
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 [email protected]: http://drupal.org/node/293188#comment-1282186)

Initial Title
Add "first" and "last" classes on blocks

Initial Tags
drupal

Initial Language
PHP