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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
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
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