Hi,
The above code isn't correct. Consider the following menu structure:
Level1_1 --- Level1_2 --- Level1_3 --- Level1_4
***** Manual signatures are NOT allowed *****_ Level2_1
***** Manual signatures are NOT allowed *****_ Level2_2
***** Manual signatures are NOT allowed *****_ Level2_3
***** Manual signatures are NOT allowed *****_ Level2_4 -> Level3_1
***** Manual signatures are NOT allowed *****_______ Level3_2[/quote]
The problem is with Level2_4: it is the last item on level 2, but it has childrens on level 3. Your code will not add the 'last' class for Level2_4 menu item.
If you investigate the code of default.php from mod_menu, you'll find this in line #68:
Code: Select all
else if ($item->shallower) {
echo '</li>';
echo str_repeat('</ul></li>', $item->level_diff);
}
The trick is in str_repeat function: </ul></li> will be output
twice - because when the code (foreach) reaches the item
Level3_2 it will close the
li element of item
Level3_2, the
ul element of level 3 AND the last
li item on level2 + the
ul item of level2. (Comprende?
) The reason: the value of
$item->level_diff = 2 when
Level3_2 item is on the output.
(Just var_dump the $list object, and you'll see the value of level_diff variable will be 2 for the Level3_2 menu item.)
The above code inside the foreach cycle will reach this condition...
Code: Select all
if ($item->shallower or $currentitemcount == count($list)) {
$class .= 'last ';
}
... in the NEXT cycle, when it is too late to discover that we had have already got a 'last item' (on level2) 2 items before the actual menu item (Level3_2).
I hope it was clear.
Ciao.