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?
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?
Or is this something I'd have to hack?
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.
Works for me.
Is there a version that works with hard-coded links?
I'm doing this:
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.
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.
Here's how you can do this programmatically.
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.
$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.
Thanks, awesome tip. I'll probably use this on the very next project I'm working on, actually. It is a common need.
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!
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!
Hello,
If you are looking for the link to the page you should use
or if you need the full path with the domain
Best Wishes,
Mike
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
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!
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!
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);
Thank you mkly and aghouseh!
That did the trick. =)
Mr Lindau
That did the trick. =)
Mr Lindau
Yup,
Thanks @aghouseh, wasn't clear enough in my description.
Thanks @aghouseh, wasn't clear enough in my description.