3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 850 Views |
-
DataOject - testimonial

9 August 2010 at 7:59am Last edited: 9 August 2010 8:04am
Hi guys,
I am trying to create a function that displays random projects (image and text) on my About page if there is a testimonial assigned (filled out in CMS) to that project. I have the correct code for other similar functions i.e pulling the project to homepage if item is checked (in CMS) so I`m nearly there with this one.
In Page.php
public function SelectedAbout() {
return DataObject::get("PortfolioPage", "FILTER REQUIRED HERE", "RAND()", null, "");
}In PortfolioPage.php
class PortfolioPage extends Page {
static $db = array(
'Url' => 'Text',
'ProjectInfo' => 'HTMLText',
'DisplayHomepage' => 'Boolean',
'Testimonial' => 'HTMLText'
...Your help is appreciated.
Cheers,
Dave -
Re: DataOject - testimonial

9 August 2010 at 8:59am Last edited: 9 August 2010 9:04am
Hi Dave, off the top of my head, this should do what you need:
return DataObject::get("PortfolioPage", "Testimonial <>''", "RAND()", null, "");
-
Re: DataOject - testimonial

9 August 2010 at 11:02am
Thanks for that Nick. Your speedy response is appreciated. Look forward to getting my portfolio site up soon.
Cheers,
Dave -
Re: DataOject - testimonial

9 August 2010 at 7:49pm Last edited: 9 August 2010 7:56pm
This worked a treat with a very slight modification to pull only one random project with a testimonial from all the projects that had a testimonial associated with it only.
So for the good of all...
Page.php - Adding the 1 limited the set to one row (in this case random).
public function SelectedAbout() {
return DataObject::get("PortfolioPage", "Testimonial <>''", "RAND()", null, "1");
}AboutPage.ss
...
<p>$Testimonial.FirstSentence</p>
...
| 850 Views | ||
|
Page:
1
|
Go to Top |

