Add "first" and "last" classes on blocks

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:

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