Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Random Landing Pages

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

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

Page: 1
Go to End
Author Topic: 1439 Views
  • workshed
    Avatar
    Community Member
    4 Posts

    Random Landing Pages Link to this post

    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/landing3

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

    Thanks for any suggestions!

    -Bret

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Random Landing Pages Link to this post

    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

    1439 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.