selected navigation item

Permalink 1 user found helpful
Is there a way to indicate a css class for the current navigation item? I'd like to set an "active" class on the navigation link for the current page?

killroyboy
 
comfixit replied on at Permalink Reply
I believe C5 builds the navigation in such a way that the currently selected item has the following class code added to it.

class="nav-selected"


So an example of a complete nav (Well a Nav of two items About and Contact Us with About selected):

<ul class="nav-header"><li class="nav-selected first"><a class="nav-selected" href="/index.php/about/">About</a></li><li class=" "><a href="/index.php/contact/">Contact</a></li>
</ul><div class="ccm-spacer">&nbsp;</div>


This is automatically produced based on the pages included in your sitemap in C5.

In my template the following PHP code produces the example above.
<? $a = new Area('Header Nav'); $a->display($c); ?>
killroyboy replied on at Permalink Reply
killroyboy
I don't know how I didn't notice that. That brings up another question though. How do I get my index/default page to show in the navigation?
andrew replied on at Permalink Reply
andrew
We used to have an option for this in the autonav but it was buggy, so we removed it.

It does seem like people would like it back, though, so perhaps it will come back in an updated version of the autonav.
paulfeakins replied on at Permalink Reply
paulfeakins
I always come across this issue when building CMS websites in various commercial CMSs. The problem is the home page is a single node on the top level, but in the navigation you want it to appear as if it were on the first level. i.e. the same level as all its children. I didn't find any problems with the checkbox there used to be for this purpose though? Might be worth bringing that back :)
Paul.
http://www.AntropyConsulting.com
zoinks replied on at Permalink Reply
Did this ever come back?

I need this functionality and it would be nice to know if there's a simple way to do it.

I basically just need to know what to call my "current" or "selected" class in the CSS file (I hope).

Thanks,
Nate
jordanlev replied on at Permalink Reply
jordanlev
The CSS class is ".nav-selected".

If you want to add the home page to your nav, copy the file "header_menu.php" from the YOURSITE/concrete/blocks/autonav/templates/ directory to a new directory (you'll need to create this):
YOURSITE/blocks/autonav/templates/

Edit that file and add this code just above the "$isFirst = true;" line:
$homeClass = (0 == $c->getCollectionParentID()) ? 'nav-selected' : '';
echo '<li class="'.$homeClass.'"><a href="'.DIR_REL.'">Home</a></li>';

(note that you should ignore the "<?php" and "?>" tags in there -- those are put in automatically by the forum, but shouldn't actually be pasted into your code).

Now click on the autonav block in edit more (or add it to the page and then click on it) and choose "Custom Template" from the menu, then choose "Header Menu" from the list.

That should work (and you can of course change the word "Home" in the code sample so it says whatever you want).

-Jordan