Jump to content

Access child pages / auto redirect to parent page


Manalishi
 Share

Recommended Posts

Hi,

I've found this great CMS and walked through several tutorials but i haven't understood how to prevent access to my child pages and set a redirect.

My page structure looks like this:

Home
    |- Landing page
                |- Breadcrumb
                |- Image Text
                |- Template 1
                |- Template n
    |- Products


    
How can i handle the access to the child pages of the 'Landing page'? In this case, i would like to prevent the access to them and automatically redirect to the parent page (Landing page) if one of these pages are opened in the Browser.
    
localhost/project/landing-page/breadcrumb/  -> should redirect to localhost/project/landing-page/
localhost/project/landing-page/image-text/    -> should redirect to localhost/project/landing-page/

I've added the following code on top of my template PHP files but it doesn't work:

<?php
    $session->redirect("/landing-page/");
?>

I haven't tried it but also found that: http://modules.processwire.com/modules/process-redirects/
Is that the right way to handle redirects or is there a better solution out there to do that?

Thanks in advance for your help.

Link to comment
Share on other sites

You could hide the children/child pages and use the include=hidden selector: children("include=hidden")

You could use http://modules.processwire.com/modules/batch-child-editor/ (or http://modules.processwire.com/modules/process-batcher/) to hide them quickly.

If needed, you could create a checkbox field named redirect_to_the_parent_pageredirectToTheParentPage, parent_redirect, parent_page_redirect or whatever, add it to the template of the children pages, and add something like this to the bottom of the children pages template file (I have never used it but have just converted it from the code in the NB:, so I haven't tested):

<?php if($page->parent_redirect) $session->redirect($page->parent()->url); // Parent redirect if the checkbox is checked ?>

If needed, you could perhaps also use something like (haven't tested):

<?php if($page("template=children_template")) $session->redirect($page->parent()->url); ?>

<Last edit>: I guess 

<?php $session->redirect($page->parent()->url); ?> // I can't find the code button...

would be enough if you put it in the childen pages template file.

</Last edit>

NB:  sometimes I use

<?php if($page->first_child_redirect) $session->redirect($page->child()->url); // First child redirect if the checkbox is checked ?>

in a parent template file.

PS: you also have http://modules.processwire.com/modules/process-jumplinks/, in case.

Edited by Christophe
  • Like 1
Link to comment
Share on other sites

Thank you all for your help!

I tried the .htaccess redirect and this works.

The hook doesn't work for me, but I think that was my fault. Maybe I placed it on the wrong file (I placed it in the admin.php file).

I will practice more with PW.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...