but it would be nice to have it work off the page title instead
An even more organised way of doing this would be to go back to what I said about Page Types.
I assume you only want the code to work of the parent title because you want it to say something like "ParentTitle = 'Testimonials'" so there is never any risk of accidently loading content from an incorrect Page.
You could instead create a custom "TestimonialPage" for these pages, and that would be as easy as this:
/mysite/code/Testimonial.php
class Testimonial extends Page {
static $db = array(
);
static $has_one = array(
);
}
class Testimonial_Controller extends Page_Controller {
}
Change the testimonials to be this page type on the behaviors tab (at this stage, there is no difference between this and the original Page).
Then your random code can be like this:
// Get featured testimonial
function getFeaturedTestimonial() {
return DataObject::get_one('Testimonial', null, false, 'RAND()');
}
Easier to follow, you will always only get Testimonials returned by the code, and you also get the option of adding specialized fields and styling to this page type should you wish.
Just alot more organised.
Cheers
Aaron