Jump to content

Making A Child Page The 'main' Page


Travo
 Share

Recommended Posts

Hello!

I am new to ProcessWire (obviously) and need some guidance, as I don't even know how to put what I'm trying to do into phrases Google could understand. Basically, I have a structure like this:

Main page
--> Cars
--> --> Volvo
--> --> Iveco

So, the Volvo and Iveco are both 'Cars' child pages. Following me? Ok, great!

What my goal has been for the last hour is basically trying to make 'Volvo' the main page when 'Cars' is clicked.

I'll try to make it simpler:

When I click on 'Cars', I want to see 'Volvo'. I don't want 'Cars' to be a separate page. I want 'Cars' to be VOLVO and IVECO!

Link to comment
Share on other sites

Hi Tramvai and welcome to PW.

This can be accomplished easily with a redirect. Place this in the template file that is connected to your Cars page:

$session->redirect($page->children->first()->url);

Of course you could also be more specific about the page that it redirects to, but in this example it will always go to the first child of the parent page.

  • Like 1
Link to comment
Share on other sites

Thanks for the fast response guys! Redirect was in my mind, but I honestly thought there's a better way to do it. And to remove it from displaying in the menubar list I could just rewrite the code to ignore the first entry, yeah?

Thanks again. :)

Link to comment
Share on other sites

Just to explain the difference between what diogo and I wrote. His is simpler, but mine is more descriptive. child on it's own will always be the first child. With children, you can further select last(), or use eq(n) to choose the exact one in the list of children by its numerical order index.

Hope that helps.

  • Like 2
Link to comment
Share on other sites

And to remove it from displaying in the menubar list I could just rewrite the code to ignore the first entry, yeah?

If you would like mypage/cars not to show up in lists and searches go to edit -> settings and tick the box hidden. Depending on how you render your menu/navigation the page won't show up anymore.

But note that its url (the one with the redirect) will only be accessible if someone enters the url directly into the browser.

Link to comment
Share on other sites

If you would like mypage/cars not to show up in lists and searches go to edit -> settings and tick the box hidden. Depending on how you render your menu/navigation the page won't show up anymore.

But note that its url (the one with the redirect) will only be accessible if someone enters the url directly into the browser.

Hey! Currently, my menubar gets all the pages and lists them (almost the same way it was by default). When I hide the page in my settings, it really messes up my non-hardcoded menubar.

To hide the 'first' page in the children pages list, I just hid the first entry, since by default, it is the first one and shouldn't really screw things up.

...

As I was writing this, I could also make a check that would compare the child page names against the parents name and hide if true. :)

Great support on this forum, thanks a lot! Glad I found ProcessWire. I previously tried WordPress (didn't really match my requirements theming-wise and was too cluttered with stuff my page would never use). I also tried ForkCMS (also didn't have the flexibility of ProcessWire). :)

  • Like 1
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...