17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1243 Views |
-
Random Landing Pages

1 October 2008 at 9:36am
Hi-
We have a site with different landing pages, which are being used to track ad responses from some tv commercials and print ads. The home page of the site currently uses one of the landing pages as the home page, but we'd like to randomly rotate between the three pages.
So, for example:
domain.com/landing1
domain.com/landing2
domain.com/landing3How can we, when loading the home page, randomly choose one of those to which we can redirect?
Thanks for any suggestions!
-Bret
-
Re: Random Landing Pages

1 October 2008 at 12:02pm
When the user hits the domain, they'll go to the page "home", which should be set up as a custom page type - that being HomePage.
For the other pages, you'll want to give them a custom page type as well, something like LandingPage.
Here's example code:
class HomePage extends Page {
}
class HomePage_Controller extends Page_Controller {
// Get a random LandingPage from the site tree and redirect to it
function index() {
$randomLandingPage = DataObject::get('LandingPage', '', 'RAND()', '', 1);
if($randomLandingPage) {
Director::redirect($randomLandingPage->Link());
}
}}
Then, you need to create LandingPage as another page type and apply it to pages in the CMS site tree that you want to be candidates to be redirected to.
Cheers,
Sean
| 1243 Views | ||
|
Page:
1
|
Go to Top |


