Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Random Landing Pages

Go to End

2 Posts   1780 Views


Community Member, 4 Posts

1 October 2008 at 9:36am


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:

How can we, when loading the home page, randomly choose one of those to which we can redirect?

Thanks for any suggestions!



Forum Moderator, 922 Posts

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) {


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.