How Do I Add a Class to First / Top Level Links in Autonav?
Permalink 1 user found helpful
I have a jquery menu script that requires that I add a class to the first (TOP) level links within the menu. I am customizing the autonav for a theme.
I know that I have to edit the file within theme: /mytheme/blocks/autonav/templates/custom_menu.php
How do I add a class to the top-level links?
I know that I have to edit the file within theme: /mytheme/blocks/autonav/templates/custom_menu.php
How do I add a class to the top-level links?
Here is the template:
https://raw.github.com/jordanlev/c5_clean_block_templates/master/aut...
Copy all of that and paste it into your custom_menu.php file (overwriting everything you already have there). Then, search for "if ($ni->is_first)" (about 3/4 the way down the page). Remove the comments around this chunk of code -- so you're changing this:
/* if ($ni->is_first) { //class for the first item in each menu section (first top-level item, and first item of each dropdown sub-menu) $classes[] = 'nav-first'; } */
...to this:
(you're not really changing anything, just deleting the "/*" line and the "*/" line).
Now your autonav menu will have the nav-first class on the first item in each level.
If you only want the "nav-first" class on the first item of a dropdown menu, change this line:
...to this:
If you want a different class name, change this line:
...to this: