[themes] setting class on primary links

Michael Booth mike at michaelfbooth.com
Thu Aug 28 00:06:06 UTC 2008


On Aug 27, 2008, at 3:22 PM, Jeremy Weiss wrote:
>
>> Currently I'm calling the primary nav in my theme like so:
>
> print theme('links', $primary_links, array('class' => 'links primary- 
> links'))
>
>> But when it's displayed Drupal is assigning what appear to be  
>> random classes to the list items, like:
>
> li class="menu-144
>
>> What's the easiest way to go about applying the desired css to  
>> these links? Is there a way to tell Drupal what class to assign?
>>

If I'm reading the theme_links() source code correctly, those class  
names are coming from the keys in the $primary_links array. Try  
printing out the $primary_links array and see what it looks like -- I  
like to install Devel module and then do something like

  dpm($primary_links);

or if that doesn't work, try using dprint_r($primary_links) or  
drupal_set_message(dprint_r($primary_links, TRUE))

If I'm right, you'll find your "apparently random" class names as keys  
in that array.

As for changing the classes, one way would be to fiddle around with  
the $primary_links array before you call the theming function. Another  
way, which might be better, is to write a custom theming function for  
your links. You can either call that function directly from your theme  
or give it a name like phptemplate_links() or  
yourthemenamehere_links() to override Drupal's default definition of  
theme_links().

You can find theme_links() itself in includes/themes.inc if you want  
to steal ideas from it.

   mechfish








More information about the themes mailing list