Redirect Parent Page to FIRST child page

Permalink 1 user found helpful
Let's say a client wants to use the parent nav element for organization and not as an actual page.

For Example:

-Product 1
--About Product 1
--Pictures
--More Info

In this case they would want 'Product 1' to redirect to 'About Product 1' so that the parent page is never seen.

Is this possible in the concrete5 dashboard?

BrendanPureVision
 
BrendanPureVision replied on at Permalink Reply
BrendanPureVision
Or is this something I'd have to hack?
aghouseh replied on at Permalink Reply
aghouseh
You just need to add an attribute of type "checkbox" with the Handle set to "replace_link_with_first_in_nav". Then go to the parent page and enable that attribute and it will replace the parent link in the autonav with the first child.
mkly replied on at Permalink Reply
mkly
Works for me.
zoinks replied on at Permalink Reply
Is there a version that works with hard-coded links?

I'm doing this:
<a href="<?=$this->url('print/ads');?>" rel="dropmenu1">Print</a>

And it just goes directly to the page for obvious reasons. I'd prefer NOT to do a javascript page redirect, but it looks like I might have to.
dzimney replied on at Permalink Best Answer Reply
dzimney
Here's how you can do this programmatically.

$child = $c->getFirstChild();
$cID = $child->getCollectionID();
header('Location:' . Page::getCollectionPathFromID($cID));


I had a need to do this rather than using the "replace_link_with_first_in_nav" because I wanted all pages of a certain type redirect to their child pages. This was used for a set of drop down menus. I wanted users to be able to add more menus, but force those pages to do the redirect rather than requiring the attribute to be set on each page.
zoinks replied on at Permalink Reply
Thanks, awesome tip. I'll probably use this on the very next project I'm working on, actually. It is a common need.
MrLindau replied on at Permalink Reply
This code worked fine for me about 2 hours, then it just stopped working. I admit I did some modifications to it but not that many. And when I went back to the basic code it just doesn't work. I have cleared the cache multiple times but still no luck.

The problem now is that i still have the "index.php" in the URL as it is on a development server. But the url that comes out of getCollectionPathFromID($cID) is just the part from after "index.php".

I guess this will probably work when I enable pretty URL:s but then it shouldn't have worked before either. I just want to know how it can work the first times and then nothing, now I just get the 404.

Any ideas are appreciated, thanks!
mkly replied on at Permalink Reply
mkly
Hello,
If you are looking for the link to the page you should use
Loader::helper('navigation')->getLinkToCollection($page);

or if you need the full path with the domain
Loader::helper('navigation')->getLinkToCollection($page, true);


Best Wishes,
Mike
MrLindau replied on at Permalink Reply
Hi Mike!

I didn't get that to work either, then again I might be doing it wrong. But is there a way to get the full path with domain using the $cID ? $page wasn't the same as $cID as I first thought.

tnx!
aghouseh replied on at Permalink Reply
aghouseh
Full path to the domain would be what mkly said, but adding in the page object load.

$page = Page::getByID($cID);
Loader::helper('navigation')->getLinkToCollection($page, true);
MrLindau replied on at Permalink Reply
Thank you mkly and aghouseh!

That did the trick. =)

Mr Lindau
mkly replied on at Permalink Reply
mkly
Yup,
Thanks @aghouseh, wasn't clear enough in my description.