Just in case anyone was wondering. Here is a simple way that you can have random content show up, from more than one parent page, with the Random Content Widget.
In your RandomContentWidget.php, add more parent pages to the array, naming them whatever you want.
static $db = array(
'WidgetTitle' => 'Varchar(255)',
'ParentPage'=>'Varchar(255)',
'ParentPage2'=>'Varchar(255)',
'ParentPage3'=>'Varchar(255)',
'ParentPage4'=>'Varchar(255)',
'ParentPage5'=>'Varchar(255)'
);
Then add more fields to the admin widget
function getCMSFields() {
// TODO: Use TreeDropdownField when it's fixed
return new FieldSet(
new TextField('WidgetTitle', _t('TITLE','Title (optional)')),
new TextField('ParentPage', _t('PARENTPAGE', 'The URL segment of the parent page to display a random child of.')),
new TextField('ParentPage2', _t('PARENTPAGE2', 'The URL segment of the second parent page.')),
new TextField('ParentPage3', _t('PARENTPAGE3', 'The URL segment of the third parent page')),
new TextField('ParentPage4', _t('PARENTPAGE4', 'The URL segment of the fourth parent page')),
new TextField('ParentPage5', _t('PARENTPAGE5', 'The URL segment of the fifth parent page'))
);
}
With that we need to change the RandomContent function to randomly pull a parent page that has been defined. We will create an array with all the parent pages in them. As seen below. Then in the Array_rand function pull the total number of parent pages that you have. Which in this example there are five. Last but not least change "Convert::raw2sql($this->ParentPage)" to "Convert::raw2sql($randomParentPage)"
function RandomContent() {
$allParents = array($this->ParentPage, $this->ParentPage2, $this->ParentPage3, $this->ParentPage4, $this->ParentPage5);
$rand_keys = array_rand($allParents, 5);
$randomParentPage = $allParents[$rand_keys[0]];
$parent = DataObject::get_one('SiteTree', "URLSegment = '". Convert::raw2sql($randomParentPage) . "'");
if(!$parent) {
return false;
}
return DataObject::get('SiteTree', "ParentID = $parent->ID", "RAND()", "", 1);
}
And that should do it. Then in your RandomContentWidget.ss call which ever info you would like to be shown. For my website i have an image that is being pulled with the date created for each random page like so.
<% control RandomContent %>
<a href="$Link"><img src="$Image.URL" width="206" /></a>
CREATED: $Date
<% end_control %>
I hope you find this useful and if anyone can expand on it, please share.