Page hierarchy: pass-through pages?

Permalink
Imagine a navigation with an item that, when clicked on, takes you to its first child page.

So it isn't necessary that the top-level page exists (except in the navigation).

You click on "page" but instead of going to
/page
you go to
/page/first-child

How would this be set up, ideally?

Thanks for your help!

kirkroberts
View Replies:
kirkroberts replied on at Permalink Reply
kirkroberts
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

How can this be achieved?
Remo replied on at Permalink Reply
Remo
If you understand German, I've posted an approach on Concrete5.ch:

http://www.concrete5.ch/board/?topicID=21...
kirkroberts replied on at Permalink Reply
kirkroberts
I can't read German, but I guess Google Translator does a passable job. Totally messes up the code, though :-)

So I get this from that thread (taking out the conditionals...):

$nh = Loader::helper('navigation'); 
$subPage = $c->getFirstChild(); 
$pageLink = $nh->getLinkToCollection($subPage); 
print("the child link: " . $pageLink);


But it doesn't work, giving me this error:

Fatal error: Call to a member function getCollectionPath() on a non-object in [...]/concrete/helpers/navigation.php on line 36

I bet this would be easy if only I knew what I was doing :-)
Remo replied on at Permalink Reply
Remo
the function which gets called should have a parameter, $page in my example.

I think it should be $page->getFirstChild()

(haven't tested it)
kirkroberts replied on at Permalink Reply
kirkroberts
Whoops, turns out the previous code *did* work.

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.
kutis replied on at Permalink Reply
kutis
thanks kirk,

the code needs a minor fix though...

<?php  
defined('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);
}
?>
pixelfish replied on at Permalink Reply
pixelfish
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.

am i doing something wrong?
mbayhylle replied on at Permalink Reply
mbayhylle
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 '#'.
kirkroberts replied on at Permalink Reply
kirkroberts
@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.
stokini replied on at Permalink Reply
stokini
As an alternative, you could use css to make the top-level links *appear* not to be links:

.nav > li a:hover { cursor: default; }
PurpleEdge replied on at Permalink Reply
PurpleEdge
If you look at the left menus on this site...

http://thenorthernbeaches.com.au...

..the main links are simply category headers.

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?
zoinks replied on at Permalink Reply
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.
zoinks replied on at Permalink Reply
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.

Thank you!
smilenstacy replied on at Permalink Reply
How do you add this "replace_link_with_first_in_nav" attribute? I can't seem to find it anywhere.

Thanks!
kirkroberts replied on at Permalink Reply
kirkroberts
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?
smilenstacy replied on at Permalink Reply
Yup, works perfectly, thanks so much!
DtotheOR replied on at Permalink Reply
DtotheOR
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?
kirkroberts replied on at Permalink Reply
kirkroberts
DtotheOR, for me it's just been a lot of looking around the forums and digging around in the core files.

I think that property was suggested early on by a power user (Remo?) and the Concrete5 team eventually added it to the core.