Skip to content

Instantly share code, notes, and snippets.

@brentini
Created August 2, 2012 20:56
Show Gist options
  • Save brentini/3240578 to your computer and use it in GitHub Desktop.
Save brentini/3240578 to your computer and use it in GitHub Desktop.
Joomla: first and last menu item classes
<?php
$last_level_one_id = 0;
for($j=count($list)-1; $j>0; $j—){
if($list[$j]->level == 1){
$last_level_one_id = $list[$j]->id;
break;
}
} $first_start = true;
?>
Then we find the code below, this is the bit that adds classes to the menu elements and modify as shown below:
if ($item->parent) {
$class .= ' parent';
}
if (!empty($class)) {
$class = ' class="'.trim($class) .'"';
}
We will add a few lines of code between them to get the ‘first’ and ‘last’ class in the menu items. Our new block will look like:
if ($item->parent) {
$class .= ' parent';
}
//start first last changes
if($first_start){
$class .= ' first';
$first_start = false;
}else if ($item->shallower || $item->id == $last_level_one_id ) {
$class .= ' last';
}
if ($item->deeper) {
$class .= ' deeper';
$first_start = true;
}
//end first last changes
if (!empty($class)) {
$class = ' class="'.trim($class) .'"';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment