Add First and Last Classes to Nav Links

Events happening in the community are now at Drupal community events on www.drupal.org.
doors's picture

In Openpublish 2.0 the main menu links had a class for the forst link and last link.

Openpublish 2.2 does not have these classes which are essential for some creative css work.

How can I add these class to the first and last links in the menu?

I see that print theme('openpublish_menu', $expanded_primary_links); is being used instead of print theme('links', $primary_links, array('class' => 'links primary-links')) which doesn't seem to use the openpublish_theme_menu_item() function.

How can I accomplish this?

Comments

Good call for the first /

tirdadc's picture

Good call for the first / last class in the expanded menu. Since OP 2.1 it is enabled by default, but should it not be set, the theme will use the regular $primary_links.

Here's a way to add these classes for now by adding some logic to your tpl:

1 - copy openpublish-menu.tpl.php from sites/all/modules/openpublish_core/openpublish_menu to your active theme (openpublish_theme or whatever child theme you may have)

2 - add this right after lines 6-7 where $title_link is set:

static $i = 1;
$position_class = "";
if ($i === 1) {$position_class = "first";}
elseif ($i == sizeof($expanded_primary_links)) {$position_class = "last";}
$i++;

3 - change this line:
<li class="first-level <?php print ($top_item->active ? $top_item->active : "off"); ?>">
to
<li class="first-level <?php print ($top_item->active ? $top_item->active : "off"); ?> <?php print $position_class; ?>">

Later on I will take care of moving this into the preprocessor that generates $expanded_primary_links.

I went ahead an installed

doors's picture

I went ahead an installed Nice Menu because I couldn't get any answers.

Thanks for the response. I might use this solution for my other project.

OpenPublish

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: