Found out that you can create a custom page attribute (checkbox) with a handle of "replace_link_with_first_in_nav" and the AutoNav block will use the first child's link in place of the parent. Good!
But I'm also wondering if this is possible:
With a structure like this...
/section/
/section/page/
*any* link to /section/ will go to /section/page/.
eg if someone types it in
So, if anyone wants to force a page to go to its first child page this code at the very top of a page type will do the trick:
defined('C5_EXECUTE') or die(_("Access Denied."));// redirect to first child$nh= Loader::helper('navigation');$subPage=$c->getFirstChild();$pageLink=$nh->getLinkToCollection($subPage);header('Location: '.$pageLink);
Not sure what would happen if the first child happened to be an external link (not a page). Use with caution.
Thanks for your help, Remo!
ps - if there is a way to do this with c5's core (aliases?) I'd love to know about it.
<?phpdefined('C5_EXECUTE') or die(_("Access Denied."));// redirect to first child$nh= Loader::helper('navigation');$subPage=$c->getFirstChild();if($subPage){$pageLink=@$nh->getLinkToCollection($subPage);header('Location: '.$pageLink);}?>
Hi, I copied your code Kutis and it works but now my parent link is not selected as active.
It has an 'a' class of 'nav-path-selected' but so does the 'home'. So if i add a style to that class both the home and portfolio page will have the selected class.
I tried copying this and it wouldn't work. I basically want the top-most link (parent link) to be inactive on the navigation. So far, I haven't been able to find anything that works.
the site ishttp://www.hawkletsxc.org/c5dev and what the coach wants is for the parent item in the navigation to not link to anything or somehow link to '#'.
@mbayhylle
If I understand you correctly, this technique won't work for what you're trying to do. This is only if you want the parent item to still be a link, but have it link to the first child item (so two links in the nav go to the same page). The code above is a safeguard in case someone types the address of the parent item in, or has a direct link to it somehow. Otherwise, the auto-nav block can take care of the linking (see the first comment in this thread).
I'm not sure why someone would want a nav link to not go anywhere. As a user I find that frustrating. But I understand you might not be calling the shots :-)
For what you're trying to do, if all top links are to be inactive you could potentially template the auto-nav block to do that. Have it omit the link tags on the first pass through.
Most other cms allow for the creation of such links, I think it would be handy to have this capability in Concrete5. The alternative is to go to a sub-page listing the sub-categories, but I find this a bit superfluous?
I think this is the same question/problem I'm having so I'm just posting in this thread until I have time to read it (so it is easier for me to find this page again later on)... hope you found a solution.
I want my Parent to redirect to the first Child in my Breadcrumbs navigation.
Awesome! For anyone who doesn't understand, this works for DIRECT LINKING (as opposed to auto-nav). For the auto-nav to redirect to the First Child, you need to add the attribute "replace_link_with_first_in_nav" as a checkbox and then add add it it to your Parent as a Custom Attribute.
BUT, if you're going to have other kinds of linkage beside an auto-nav that you want to redirect to that First Child, too, then you just make a special Page Type for that Parent and the full template is basically this code Kirk has come up with. But, as Kutis pointed out, you need to wrap it in <?php ?> tags, obviously.
First you need to create the page property/attribute.
In the admin area / dashboard look for Page Types and Page Attributes.
There you can create a checkbox/boolean attribute and make sure the attribute handle matches the replace_with_first_.... text (sorry, forgot to copy exactly what it is before I started replying :-)
Then on any given page in the Page Properties you can select that attribute.
Does that help?
Thank you so much for this information! How did you figure out that there is a handle that does this functionality? Is there some file that has a list of inactivated handles?
But I'm also wondering if this is possible:
With a structure like this...
/section/
/section/page/
*any* link to /section/ will go to /section/page/.
eg if someone types it in
How can this be achieved?