Show top level parent in side navigation

Permalink
Hi there,

I have a layout in which there are two nav bars per page. One is the main navigation bar which shows only the top level pages across a top horizontal navigation bar. When you click onto one of these pages, the side navigation bar will show all of the child pages.

This works fine, the settings are:

Display Pages: at the second level.
Sub pages to Display: Relevant sub pages.
Sub-Page Levels: Display sub pages to current+1

But what I also want is, lets say we go onto Contact Details, and the only sub page is Contact Form, I would like to have at the top of the navigation bar "Contact Details" and then the sub pages listed below it.

How would I go about this? Would it be a case of modifying the auto-nav in anyway or is there a snippet I can post to add a link to the current page? I would preferably have it in the same UL appearing at the same level as the second level pages.

I.e,

Top Level Parent
Sub Page 1
-Sub Sub Page 1
-Sub Sub Page 2
--Sub Sub Sub Page 1
Sub Page 2
Sub Page 3

Rather than:

Top Level Parent
-Sub Page 1
--Sub Sub Page 1
--Sub Sub Page 2
---Sub Sub Sub Page 1
-Sub Page 2
-Sub Page 3

Do any of you have any ideas how this would be possible?

Any feedback is appreciated.

Warm regards,
Adam

Imdsm
 
pvernaglia replied on at Permalink Best Answer Reply 1 Attachment
pvernaglia
Try this template, put it in blocks/autonav/templates and then select it for the auto nav block you have in your sidebar
Imdsm replied on at Permalink Reply 1 Attachment
Imdsm
Thanks, that works great, except for when there are no sub pages and then it doesn't show the parent. I'll take a look at the file and I'm sure I'll figure it out. But thanks!

Edit: I've now modified the file, I've added this for the top link even when the page has no sub pages:

if (count($aBlocks) == 0) 
{
   $parentPage = $c->getCollectionName();
   $link = $nh->getLinkToCollection($c);
   echo("<ul class=\"nav\">");
   echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" ' . $target . ' href="' . $link . '">' . $parentPage . '</a>');
   echo("</li></ul>");
}


and I've fixed a small bug your code had, where it was using the parent path for a link instead of $nh->getLinkToCollection($pageHere);

// Add parent page to top of menu            
$page=Page::getByID($_c->getCollectionParentID());
$parentPage = $page->getCollectionName();
$parentLink = $nh->getLinkToCollection($page);
if ($c->getCollectionID() == $page->getCollectionID()) {
   echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" ' . $target . ' href="' . $parentLink . '">' . $parentPage . '</a>');
} elseif ( in_array($c->getCollectionID(),$selectedPathCIDs) && ($c->getCollectionID() != HOME_CID) ) {
   echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $parentLink . '" ' . $target . '>' . $parentPage . '</a>');
} else {
   echo('<li><a href="' . $parentLink . '" ' . $target . ' >' . $parentPage . '</a>');
}


Thanks for giving me the file, it's been very helpful.

Warmest regards,
Adam

P.S, attached is the new file if anyone is interested
ProjbyP replied on at Permalink Reply
ProjbyP
I used your template and it worked like a charm, but ... the top level link in the sidebar is using the wrong URL - instead of going to -- http://unioncountywestendfair.com/index.php/exhibitors/... -- it's missing the "index.php" and ends up returning a 404 (page not found) error.

Any help would be greatly appreciated!
Thank you.
simpleweb replied on at Permalink Reply
If you are using Apache as your web server try enabling pretty urls in the system settings of the C5 dashboard. Then if the .htaccess file gets written you are ok, otherwise you have to do it manually with any text editor you prefer.

Doing so any url requests that don't include index.php will be automatically redirected to the right url.
sombetzki replied on at Permalink Reply
sombetzki
Hi, I tried to get the template working, but I placed it at the appropriate place, but it doesn't show up when I edit my autonav block.
Any idea how this is possible?

Thanks