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.

We've moved the forum!

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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Random order DataObject front end


Go to End


11 Posts   9866 Views

Avatar
pinkp

Community Member, 182 Posts

14 May 2011 at 10:57am

many thanks!!!!!! worked like a charm, although it had a syntax error at first the function needed to be:

function RandomSlideshowItems() { 
   return DataObject::get("SlideshowItem", "", "RAND()", ""); 
} 

I guess I should do a few more basics! thanks for the rapid response.

-----

On another note is it possible to limit the amount of data objects that are pulled from the DB, i.e. I upload 10 images but only 5 random images are chosen to be shown in the slideshow?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

15 May 2011 at 4:00am

The fifth argument is the limit.

Avatar
pinkp

Community Member, 182 Posts

16 May 2011 at 12:31am

Changing the code to this allowed me to display a limited number of images sourced from my uploads and chosen at random. The result is a slideshow which will always have varied content, perfect!

 function RandomSliders($num = 3) { 
   return DataObject::get("Slider", "", "RAND()", "",$num); 
} 

Go to Top