AutoNav Help Please
Permalink
I am trying to create a modified autonav view.php because I need to enclose the main menu within two UL's as such:
The problem I am having is I need to be able to count the Parent level Items so I can close the first UL for left menu and open the UL for the right menu. I have not been able to figure out where I need to put this action as I tried counting levels, but if a parent has children my count is all off. There will only be three parent level items in each of the two UL's (3 left & 3 right). My head hurts now... Please Help!
Current view.php:
<div id="main_menu"> <ul class="menu left"> <li><a href="#">Get Connected</a> <ul> <li><a href="#">Lorem Ipsum 3</a></li> <li><a href="#">Lorem Ipsum 3</a></li> <li><a href="#">Lorem Ipsum 3 </a></li> <li><a href="#">Lorem Ipsum 3</a></li> </ul> </li> <li><a href="#">About us</a> <ul> <li class="active_sub"><a href="#">Lorem Ipsum 1</a></li> <li><a href="#">Lorem Ipsum 1</a></li> <li><a href="#">Lorem Ipsum 1</a></li>
Viewing 15 lines of 40 lines. View entire code block.
The problem I am having is I need to be able to count the Parent level Items so I can close the first UL for left menu and open the UL for the right menu. I have not been able to figure out where I need to put this action as I tried counting levels, but if a parent has children my count is all off. There will only be three parent level items in each of the two UL's (3 left & 3 right). My head hurts now... Please Help!
Current view.php:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $aBlocks = $controller->generateNav(); $c = Page::getCurrentPage(); $containsPages = false; $nh = Loader::helper('navigation'); //this will create an array of parent cIDs $inspectC=$c; $selectedPathCIDs=array( $inspectC->getCollectionID() ); $parentCIDnotZero=true; while($parentCIDnotZero){ $cParentID=$inspectC->cParentID; if(!intval($cParentID)){ $parentCIDnotZero=false; }else{
Viewing 15 lines of 69 lines. View entire code block.
Jon,
Thanks for that information, I am going to try it out with the check boxes...
How will this affect sub pages? If I have "About" as a parent on Left, and "Staff" as a child of "About", does "Staff" need to have the Left check box selected as well?
Thanks for that information, I am going to try it out with the check boxes...
How will this affect sub pages? If I have "About" as a parent on Left, and "Staff" as a child of "About", does "Staff" need to have the Left check box selected as well?
Yep - every page on your site that you want to appear in one of the navs will need a checkbox checking.
Let me know how you got on!
Jon
Let me know how you got on!
Jon
Jon,
That worked great! I can see how this has great potential down the road.
Now I need to tweak the left & right autonav view.php a little more as the main menu that these two files creates need to be just two levels, but if there is a third level, I need the second level to be the one with the nav-selected class attached for the menu styling to work right. I had hoped that just leaving the check box empty on level three would do the trick, but it does not. It only keeps it from displaying, but therefore I have nothing in that menu as the active level which throws the styling all out of whack. I am thinking that I somehow need to change this:
But I am not sure how.
Thanks again.
That worked great! I can see how this has great potential down the road.
Now I need to tweak the left & right autonav view.php a little more as the main menu that these two files creates need to be just two levels, but if there is a third level, I need the second level to be the one with the nav-selected class attached for the menu styling to work right. I had hoped that just leaving the check box empty on level three would do the trick, but it does not. It only keeps it from displaying, but therefore I have nothing in that menu as the active level which throws the styling all out of whack. I am thinking that I somehow need to change this:
if ($c->getCollectionID() == $_c->getCollectionID()) { echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>'); } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) ) { echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>'); } else { echo('<li><a href="' . $pageLink . '">' . $ni->getName() . '</a>'); } $lastLevel = $thisLevel; $i++;
But I am not sure how.
Thanks again.
The tidiest way I can think of, is to use a custom select attribute, or two custom checkbox attributes. I think I prefer the checkbox approach, because it means you can have many more navs than just left and right and put each page into more than one nav (eg. a footer nav or header nav too)
So create your 2 checkboxes, one called leftNav and one called rightNav and have them display on all of your page types by default. Then, on each page, tick the relevant box, so it appears in the correct nav.
Then, create 2 new autonav templates, one called leftNav.php, the other called rightNav.php and copy the view.php code into them. Roughly on line 25, you should find the following code:
change this to:
and the same idea for the right nav. Then you can add two autonavs, one using the the leftNav template and the other using rightNav.
Make sense?
If you _really_ want to do it by counting, then get back to me and I'll tell you how, but I think this gives you more flexibility for both this site and future sites...
Jon