Jump to content

setting the homepage


PeterDK
 Share

Recommended Posts

Hi!

Building my first site with processwire and have a few questions, I'll keep it at one per post ;-)

First up 'homepages'.

I have a site root with children: 'nl', 'en', 'de', 'fr'.

Under 'nl' I have a page called 'overzicht'.

Now that is the real homepage of my site!

How do I redirect 'root' to 'nl' and 'nl' to 'overzicht'.

If someone visits 'en', they should see the 'overview' page (a child of 'en')

the structure:

  • root (should redirect to nl)
    • nl (should redirect to overzicht)
      • overzicht
      • page20
      • Page40
    • en (should redirect to overview)
      • overview
      • ...
    • fr
    • de
Link to comment
Share on other sites

Hi PeterDK!,

Welcome to ProcessWire and the forums! Nice to have you.

OK, to your question. To redirect to the first child of a parent page, you can add the following code to the template file of the template of the landing page (in your case "root" and "en"):

This code first checks to see if the landing page has children. If it does, it redirects to the first child's URL

if($page->numChildren) $session->redirect($page->child()->url);

OR

This code directly redirects to the first child of the landing page (i.e. the parent page) without checking if there is a child first...the idea being if you wanted to redirect, you must have checked that there is a child to redirect to! :-)

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

These code are from the threads below. There are other ways to redirect to a particular child; Please read the threads:

http://processwire.com/talk/topic/15-how-do-i-create-a-page-that-redirects-to-its-first-child/

http://processwire.com/talk/topic/2561-hide-landing-page-keeping-children-visible/

By the way, there could be other (better?) ways to organise your multilingual site rather than using a redirect on the homepage to nl. Feel free to Google our forums (e.g. multilingual site:processwire.com/talk OR EVEN blah blah site:processwire.com). Others may chip in.

<i-digress>This is post #1000 for me!!!</i-digress>

  • Like 2
Link to comment
Share on other sites

Hi PeterDK & welcome to the forums.

When reading this, a question comes to my mind: Did you know ProcessWires built in Multi-Language-Support?

Especially at first, how you can use Multi-Language-Urls and the Multi-Language-Fields?

So, it may be you need to use the hirarchy like you have shown in your post, but I first want to ask if it could be a better solution to use the built in Multi-Language-Tools.

If you need to go with your structure like shown above, you may use

$session->redirect($url);

in your home template. To redirect to nl/overzicht/

$session->redirect('/nl/overzicht/');

You can find these and many other at the CheatSheet. (You have to click 'advanced' at the top right to see more methods/properties)

------

EDIT: Generic url with redirect, like Kongondo has shown just a few seconds before my post, is a better solution!

BTW: congrats to your 1.000 post Kongondo ^-^

  • Like 3
Link to comment
Share on other sites

Possible solution with the built in Multi-Language-Tools:

You are able to create a structure like that:

set nl as your default language, create one tree with your page structure:


  • root (doesn't have content or a language but redirects to the first child, if no language is set in cookies, browser or else, to default language nl)
    • overzicht
    • page20
    • Page40

For all other languages (de, fr, en, etc.) you can fill and edit the content on the same pages in the backend with Multi-Language-Fields.

You need to put a language switcher onto your page / into your menu and you are done.

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