21487 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 433 Views |
-
Randomly load ChildrenWithLimit

11 July 2009 at 4:15am
I am using the following code to pull 2 children of the StaffHolderpage into the Homepage.
Page.php:
function ChildrenWithLimit($limit = 2) {
return DataObject::get('Page', "ParentID = $this->ID", '', '', $limit);
}Homepage.ss:
<% control Page(about-us) %>
<ul id="StaffList">
<% control ChildrenWithLimit %><li>
<div class="staffname"><a href="$Link">$Title</a></div>
<div class="staffphoto">$Photo</div>
<div class="staffdescription"><p>$Content.FirstSentence</p></div>
</li>
<% end_control %>
<% end_control %>
But what I hope to do, is to randomly choose 2 of these. Is this possible? how would it be done? Any help would be much appreciated. -
Re: Randomly load ChildrenWithLimit

11 July 2009 at 5:28am
Hi
Using "RAND()" for the sorting should do the trick. Eg.return DataObject::get('Page', "ParentID = $this->ID", 'RAND()', '', $limit);
-
Re: Randomly load ChildrenWithLimit

11 July 2009 at 9:02pm
Many Thanks for your help, this all seems to be working!
| 433 Views | ||
|
Page:
1
|
Go to Top |


