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

Testimonials page number and limit


Go to End


2 Posts   1691 Views

Avatar
stevanovich

Community Member, 63 Posts

30 March 2010 at 9:31pm

Edited: 31/03/2010 4:35am

Hi

I have a testimonials page up and running and want to limit the number on each page I see the in the CMS that it can limit the number to a page. Anyone any ideas to have to get pagination on the bottom and a number of articles limited?

Okay having trawled the forum site I found this but it doesn't work any reason why?

TestimonialPage.php

<?php
class TestimonialPage extends Page
{
static $has_many = array (
'Testimonials' => 'Testimonial'
);

public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Testimonials", new DataObjectManager(
$this,
'Testimonials',
'Testimonial',
array('Link' => 'Link','Author'=>'Author','Quote' => 'Quote'),
'getCMSFields_forPopup'
));
return $f;

}

}

class TestimonialPage_Controller extends Page_Controller {

}
function Testimonials() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$doSet = DataObject::get(
$callerClass = "Testimonial",
$filter = "`ParentID` = '".$this->ID."'",
$sort = "",
$join = "",
$limit = "{$SQL_start},4"
);

return $doSet ? $doSet : false;
}
?>

TestimonialPage.ss

<% if Testimonials %>
<ul>
<% control Testimonials %>
<li><a href="$Link">$Author </a><br>$Quote</li>
<% end_control %>
</ul>
<% end_if %>

<% if Testimonials.MoreThanOnePage %>
<p>
<% if Testimonials.PrevLink %>
<a href="$Testimonials.PrevLink">&lt;&lt; Prev</a> |
<% end_if %>

<% control Testimonials.Pages %>
<% if CurrentBool %>
<strong>$PageNum</strong>
<% else %>
<a href="$Link" title="Go to page $PageNum">$PageNum</a>
<% end_if %>
<% end_control %>

<% if Testimonials.NextLink %>
| <a href="$Testimonials.NextLink">Next &gt;&gt;</a>
<% end_if %>
</p>
<% end_if %>

The testimonials show but do ignore the pagination. The page number show up but don't work?

Any ideas?

Steve

Avatar
WebSpilka

Community Member, 89 Posts

4 February 2011 at 11:45pm

hi Stevanovich
You solved the problem?