Classes for first and last item menu and submenu items
I'm trying to add classes for my first and last items in my menu.
It's for my main menu which a horizontal menu, with drop downs. Each drop down is a submenu of the main nav item. I currently have 5 items in the main menu, with a max-limit of 7 items. Each item applies a "current' class when on that current page.
I'll describe the 5 items as "level 1" and their submenu as "level 2". I want the 1st and 7th item to have the class "first" and "last" respectively. But not for this to follow into the level 2. I want it to retain it's "current" class as well when on that page, and when viewing pages within it's submenu.
I want level 2 to apply the class "last" to any link which is the last link. I don't want level 2 to have a "first" class applied.
As you can see below, my menu is being populated by the same code. I need to it differentiate between a child and a parent node.
Using only one attribute statement with nested conditions means that you can and will get some empty attributes being drawn. To counter this you can wrap the attribute in an if statement that encompasses all nested conditions. Like so:
<xsl:if test="$currentPage/ancestor-or-self::node/@id = @id OR position() = 1 OR position() = last()">
<!--code pasted above -->
</xsl:if>
Classes for first and last item menu and submenu items
I'm trying to add classes for my first and last items in my menu.
It's for my main menu which a horizontal menu, with drop downs. Each drop down is a submenu of the main nav item. I currently have 5 items in the main menu, with a max-limit of 7 items. Each item applies a "current' class when on that current page.
I'll describe the 5 items as "level 1" and their submenu as "level 2". I want the 1st and 7th item to have the class "first" and "last" respectively. But not for this to follow into the level 2.
I want it to retain it's "current" class as well when on that page, and when viewing pages within it's submenu.
I want level 2 to apply the class "last" to any link which is the last link. I don't want level 2 to have a "first" class applied.
As you can see below, my menu is being populated by the same code. I need to it differentiate between a child and a parent node.
Can anybody suggest a way of doing this? I've viewed the following pages already: classes for first and last item and is it possible to specify a class for fist and last navigation item?
Cheers,
JV
Hi there,
You could try replacing the anchor code with this:
Using only one attribute statement with nested conditions means that you can and will get some empty attributes being drawn. To counter this you can wrap the attribute in an if statement that encompasses all nested conditions. Like so:
I hope that helps!
Thanks Stuart,
That works really well!
I have added the following code as I have a limit of 7 items on level 1 menu.
Thanks for your help Stuart!
No worries, glad it worked for you :)
is working on a reply...