Exclude from Main Nav but not Sidebar Nav
Permalink
I have my Main Nav set to show pages up to three levels deep.
My subpages have a sidebar nav the shows pages starting at the second level and shows pages also three levels deep.
There is one section of my site that I do NOT want the 3rd level items to show in the main navigation, however I DO need them to show on the subpage sidebar nav.
Anyone know of I way I can do this?
Thanks!
My subpages have a sidebar nav the shows pages starting at the second level and shows pages also three levels deep.
There is one section of my site that I do NOT want the 3rd level items to show in the main navigation, however I DO need them to show on the subpage sidebar nav.
Anyone know of I way I can do this?
Thanks!
But what if I only want to exclude the third tier under one section of the site? I have 3rd tier items under several sections, but only want them excluded under one section...
What about creating a page attribute for those specific pages to exclude and then maybe create an autonav template modifying the lines starting on 115 like this:
I think it would work, but not sure how efficient or practical it is.
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($_c->getAttribute('my_attribute_1')){ } else { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } }}
Viewing 15 lines of 16 lines. View entire code block.
I think it would work, but not sure how efficient or practical it is.
Hmm...is there a way to grab a page's Page Type? All of the pages I want excluded are of a particular page type.
The only problem I have with this approach is that the autonav still has to load the pages I don't want...which at this point is a couple dozen pages, but it will likely be a hundred or so over the next year or two.
This poses performance problems.
The only problem I have with this approach is that the autonav still has to load the pages I don't want...which at this point is a couple dozen pages, but it will likely be a hundred or so over the next year or two.
This poses performance problems.
I do believe so. Check out this post: http://www.concrete5.org/community/forums/customizing_c5/get-page-t...
And I think the autonav stems from root/concrete/core/controllers/blocks/autonav.php (which is where it looks for the default exclude from nav and other page attributes while loading and then returns the $navItems to the autonav block. But this would effect all instances of the autonav functionality.
This method won't work, actually after having just tested it.
The first park works, to see if the nav item is of a certain page type:
But this part here, where the autonav detects child pages and decides to open a submenu still fires. This ends up nesting every nav item inside the previous one:
The first park works, to see if the nav item is of a certain page type:
if($ni->cObj->getCollectionTypeHandle() == 'case_study') { }
But this part here, where the autonav detects child pages and decides to open a submenu still fires. This ends up nesting every nav item inside the previous one:
if ($ni->hasSubmenu) { //this part results in TRUE even though I'm not displaying the children. echo '<ul>'; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) }
So I found a solution that *should* work.
On my Main Nav, I used the attribute "exclude_subpages_from_nav" so the third level items would not show up under that one secion.
Then, on my Sidebar nav, I created a custom template that uses this line in the beginning:
The TRUE argument here makes the autonav ignore the Exclude attributes.
This works because as of right now, I don't think there are any nav items that would show up in the side bar that need to be excluded.
If so, then I need to find a better solution...
On my Main Nav, I used the attribute "exclude_subpages_from_nav" so the third level items would not show up under that one secion.
Then, on my Sidebar nav, I created a custom template that uses this line in the beginning:
$navItems = $controller->getNavItems(true);
The TRUE argument here makes the autonav ignore the Exclude attributes.
This works because as of right now, I don't think there are any nav items that would show up in the side bar that need to be excluded.
If so, then I need to find a better solution...
I tried this on my site (changing the page type handle) and it gave the correct nav structure.
foreach ($navItems as $ni) { $_c = $ni->cObj; if($ni->cObj->getCollectionTypeHandle() == 'blank'){ } else { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } }
Viewing 15 lines of 17 lines. View entire code block.
In reading your post, I think you may have missed the first else statement. I reformatted to show the logic structure.
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($_c->getCollectionTypeHandle('blank')) { } else //you may have missed this else statement and surrounding {} tags below { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else
Viewing 15 lines of 21 lines. View entire code block.
When I copy your code verbatim (changing 'blank' to 'case_study') I get nothing to output at all.
If I add echo 'true'; to your first if statement, I get every single nav item to echo out true.
When I change your first IF statement to be this instead:
I get all my nav items nested again on that third level.
Here is exactly what I have in my template:
If I add echo 'true'; to your first if statement, I get every single nav item to echo out true.
When I change your first IF statement to be this instead:
if ($ni->cObj->getCollectionTypeHandle() == 'case_study') {
I get all my nav items nested again on that third level.
Here is exactly what I have in my template:
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($ni->cObj->getCollectionTypeHandle() == 'case_study') { // echo 'true'; } else //you may have missed this else statement and surrounding {} tags below { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else
Viewing 15 lines of 21 lines. View entire code block.
1. Have you considered using a pagelist block for the sidebar nav instead of an "autonav" block. Then you could use the "exclude from nav"(all third level pages) and "exclude from pagelist"(all top level pages) attributes to get the desired result.
OR -- since it sounds like you want to include the third tier in the main nav on some pages, but not others.
2. Create one or two custom templates for the autonav block:http://c5blog.jordanlev.com/blog/2011/12/customizing-the-autonav-te...
For the record, this code has been merged into the core, so you can just copy concrete/blocks/autonav/view.php and get the same result.
My personal approach here would be two templates:
exclude top:
exclude third tier:
Hope this helps - RJ