Complex Autonav Help
Permalink
Hi,
I'm in the process of adding autonavs to my theme. However this site is quite large and has an intricate hierarchy, which is why it needs to be displayed in a certain way.
Here's an example of the site map:
HOME
- PROVINCE 1
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 2
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 3
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 4
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
---
When viewing HOME, the nav should show the following:
HOME (selected)
PROVINCE 1
PROVINCE 2
PROVINCE 3
---
When viewing any PROVINCE, the nav should show the following (we'll use PROVINCE 1 in the example):
PROVINCE 1 (selected)
CHILD 1
CHILD 2
CHILD 3
---
When viewing the province child page (for example, CHILD 1), the nav should look like this:
PROVINCE 1
CHILD 1 (selected)
CHILD 2
CHILD 3
---
When viewing the province child sub page (for example, SUB CHILD 1), the nav should look like this (same as above example - sub child parent page is selected):
PROVINCE 1
CHILD 1 (selected)
CHILD 2
CHILD 3
---
I apologize if this is a bit confusing, but that's exactly why I'm here for help. This is all referencing the exact same nav. It just needs to show up differently depending on the level youre viewing. Hopefully someone can help me figure this out!
Thanks in advance!
I'm in the process of adding autonavs to my theme. However this site is quite large and has an intricate hierarchy, which is why it needs to be displayed in a certain way.
Here's an example of the site map:
HOME
- PROVINCE 1
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 2
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 3
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
- PROVINCE 4
- - > CHILD 1
- - - - > SUB CHILD 1
- - - - > SUB CHILD 2
- - - - > SUB CHILD 3
- - > CHILD 2
- - > CHILD 3
---
When viewing HOME, the nav should show the following:
HOME (selected)
PROVINCE 1
PROVINCE 2
PROVINCE 3
---
When viewing any PROVINCE, the nav should show the following (we'll use PROVINCE 1 in the example):
PROVINCE 1 (selected)
CHILD 1
CHILD 2
CHILD 3
---
When viewing the province child page (for example, CHILD 1), the nav should look like this:
PROVINCE 1
CHILD 1 (selected)
CHILD 2
CHILD 3
---
When viewing the province child sub page (for example, SUB CHILD 1), the nav should look like this (same as above example - sub child parent page is selected):
PROVINCE 1
CHILD 1 (selected)
CHILD 2
CHILD 3
---
I apologize if this is a bit confusing, but that's exactly why I'm here for help. This is all referencing the exact same nav. It just needs to show up differently depending on the level youre viewing. Hopefully someone can help me figure this out!
Thanks in advance!
Thanks @adajad,
I appreciate the help. For the time being I'm going to hold off on implementing jQuery to make the menu work as I would like it too.
However we hope to finish up the site by the end of the next week, so assuming there isn't a simpler solution through PHP I'll probably end up utilizing your javascript to make things work.
Cheers!
I appreciate the help. For the time being I'm going to hold off on implementing jQuery to make the menu work as I would like it too.
However we hope to finish up the site by the end of the next week, so assuming there isn't a simpler solution through PHP I'll probably end up utilizing your javascript to make things work.
Cheers!
Well I'm still looking around for a solution that doesn't involve Javascript.
I came across this C5 Navigation Builder by pietschy(https://bitbucket.org/pietschy/c5_navigation_builder/... ) and thought maybe it would do the trick. I literally just ran into this and haven't looked into it deeply.
Wondering if anyone else has given it a try?
I came across this C5 Navigation Builder by pietschy(https://bitbucket.org/pietschy/c5_navigation_builder/... ) and thought maybe it would do the trick. I literally just ran into this and haven't looked into it deeply.
Wondering if anyone else has given it a try?
I believe that add-on just builds a separate nav item that does not generate from the site structure, so any additions to the site would not show. I think you can achieve what you are trying to do with a little bit of php and hard coding the autonav block in.
Without testing, I think that should do the trick.
<?php $currentID = $c->getCollectionID(); $parentID = $c->getCollectionParentID(); if ($currentID == 1) { $navRoot = 1; } else { while ($parentID != 1){ $currentID = Page::getByID($parentID)->getCollectionID(); $parentID = Page::getByID($currentID)->getCollectionID(); } $navRoot = $currentID; } $an = BlockType::getByHandle('autonav'); $an->controller->displayPages = 'custom'; // top, above, below, second_level, third_level, custom (Specify the displayPagesCID below) $an->controller->displayPagesCID = $navRoot; // <-- Specify the CID of the page. ( Gets the first level of pages under that section )
Viewing 15 lines of 21 lines. View entire code block.
Without testing, I think that should do the trick.
I tried implementing your code and upon navigating to from the homepage to the province page, I was excited to see that it seemed to be mostly working! However, as I tried to navigate deeper into the province child pages, it seemed my website would no longer load. Every page was now continuously trying to load, to no avail.
I'm not sure why I was able to load the first two pages, but now it won't load anything. When I remove the code everything loads fine.
Do you have any ideas why this may be happening?
Thanks for the help! This is exactly what I've been looking for... just need to work out the kinks.
I'm not sure why I was able to load the first two pages, but now it won't load anything. When I remove the code everything loads fine.
Do you have any ideas why this may be happening?
Thanks for the help! This is exactly what I've been looking for... just need to work out the kinks.
Beebs actually posted a really nice solution to this on another post here:
http://www.concrete5.org/community/forums/customizing_c5/display-to...
My code has a flaw in it and his seems pretty elegant/error-proof.
http://www.concrete5.org/community/forums/customizing_c5/display-to...
My code has a flaw in it and his seems pretty elegant/error-proof.
I think you can solve this by creating custom templates for the autonav block that display the current page or the parent page followed by the rest of the menu.
So for the home page and the province pages, what you want to do is set the autonav block to display only children pages, and only 1 level deep. Then in your custom template, before the first page item is outputted, you can output the link to the current page.
For the child pages, you do the same thing, but set the autonav block to show pages above the current level (by choosing "Display Pages: Beneath a particular page" and then choosing the grandparent page), and also adding the parent page link before the normal menu is outputted.
You might find this autonav template easier to work with than the built-in one:
https://raw.github.com/jordanlev/c5_clean_block_templates/master/pag...
So for the home page and the province pages, what you want to do is set the autonav block to display only children pages, and only 1 level deep. Then in your custom template, before the first page item is outputted, you can output the link to the current page.
For the child pages, you do the same thing, but set the autonav block to show pages above the current level (by choosing "Display Pages: Beneath a particular page" and then choosing the grandparent page), and also adding the parent page link before the normal menu is outputted.
You might find this autonav template easier to work with than the built-in one:
https://raw.github.com/jordanlev/c5_clean_block_templates/master/pag...
Have a look at http://www.spaceproduction.se and the menu functions and let me know if it's to you liking.
EDIT: There might be and easy fix to this, but I couldn't find one. If someone else have a nice solution then please post.