Posted By

Fake on 09/26/09


Tagged

drupal Blocks


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jmiller
pjmccormick
unravelme1


Add "first" and "last" classes on blocks


 / Published in: PHP
 

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

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)

  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.

Report this snippet  

You need to login to post a comment.