background image
Eric's picture

Today I wanted to add a unique identifier to each menu item in the primary links so I could theme each one individually. In this example, I added a incrementing class to each menu item so I could add an image via css. Here's a snippet of my theme function (found in template.php):

<?php
function MYTHEME_preprocess_page(&$variables) {
 
$linkCount = 0;
  foreach (
$variables['primary_links'] as $k => $v) {
   
$linkCount++;
   
$class = trim($v['attributes']['class'] . " nav$linkCount");
   
$variables['primary_links'][$k]['attributes']['class'] .= $class;
  }
}
?>

Is this the way you would add images to the primary links and...

Is this the way you would add images to the primary links and the drupal search box. I'm required to develop the navigation to look like this:

[ link, link, link, link, search box, link ]

This seems to be the best way so far just curious if you had an opinion or better idea for implementation?

Thanks

Martin