Last active
March 19, 2018 15:59
-
-
Save benjamin-smith/8165801 to your computer and use it in GitHub Desktop.
Custom Pagination in SilverStripe CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CustomObject extends DataObject { | |
private static $db = array( | |
'Sort' => 'Int', | |
); | |
private static $default_sort = 'Sort ASC'; | |
public function PrevNextPage($mode = 'next', $loop_around = TRUE) | |
{ | |
if ($mode==='next') { | |
$sort = $this->Sort + 1; | |
$dir = 'ASC'; | |
} else { | |
$sort = $this->Sort - 1; | |
$dir = 'DESC'; | |
} | |
$page = self::get()->filter(array( | |
'ParentID' => $this->ParentID, | |
'Sort' => $sort | |
))->First(); | |
if( ! $page && $loop_around ) | |
{ | |
$page = self::get()->filter(array( | |
'ParentID' => $this->ParentID, | |
))->sort('Sort', $dir)->First(); | |
} | |
return $page; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment