Add "first" and "last" classes on blocks


/ Published in: PHP
Save to your folder(s)

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)


Copy this code and paste it in your HTML
  1. <?php
  2. function themename_preprocess_block(&$vars, $hook)
  3. {
  4. static $counts;
  5. if(!isset($counts)) $counts = array();
  6. $region = $vars['block']->region;
  7. if(!isset($counts[$region])) $counts[$region] = count(block_list($region));
  8. $count = $counts[$region];
  9. $extremity = '';
  10. if($vars['id'] == 1) $extremity = 'first';
  11. if($vars['id'] == $count) $extremity = 'last';
  12. $vars['classes'] .= $extremity != '' ? ' ' . $extremity : '';
  13. }
  14. ?>
  15.  
  16. You need to change themename to your themplate name.

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.