Created
August 2, 2012 20:56
-
-
Save brentini/3240578 to your computer and use it in GitHub Desktop.
Joomla: first and last menu item classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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