Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » display 3 random dataobjects on frontpage

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 828 Views
  • janulka
    Avatar
    Community Member
    80 Posts

    display 3 random dataobjects on frontpage Link to this post

    I have 4 pages / categories, each with several dataobjects.

    I would like to display 3 random dataobjects from each page / category on the frontpage, how do I do it?

    thanks

  • SSadmin
    Avatar
    Community Member
    90 Posts

    Re: display 3 random dataobjects on frontpage Link to this post

    Select a random row with MySQL:

    SELECT column FROM table
    ORDER BY RAND()
    LIMIT 3

    Maybe using DataObject::get("YourDataobject",$where,"","sort") statement

    DataObject::get( $callerClass, [$filter = ""], [$sort = ""], [$join = ""], [$limit = ""], [$containerClass = "DataObjectSet"] )

    put ORDER BY RAND() in to sort field
    and set limit to 3
    should be okay.

    DataObject::get("YourDataobject",$where,"ORDER BY RAND()","","3");

    Cheers

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