Last active
March 11, 2021 13:07
-
-
Save mediabeastnz/ebf1c91220f6375b7c8f to your computer and use it in GitHub Desktop.
SilverStripe Prev / Next Controls
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
public function PrevNextPage($Mode = 'next') { | |
if($Mode == 'next'){ | |
return SiteTree::get()->filter(array("ParentID" => $this->ParentID, "Sort:GreaterThan" => $this->Sort))->sort("Sort ASC")->limit(1)->first(); | |
} | |
elseif($Mode == 'prev'){ | |
return SiteTree::get()->filter(array("ParentID" => $this->ParentID, "Sort:LessThan" => $this->Sort))->sort("Sort DESC")->limit(1)->first(); | |
} | |
else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pinkp
To avoid the "Previous" button on the first page a and "Next" at the last:
<% if Parent && $ChildrenOf($Parent.URLSegment).count > 1 %> <div> <% if $Sort > 1 %> <% loop PrevNextPage(prev) %> <a href="$Link">< Previouse</a> <% end_loop %> <% end_if %> <% if $Sort < $ChildrenOf($Parent.URLSegment).count %> <% loop PrevNextPage(next) %> <a href="$Link">Next > </a> <% end_loop %> <% end_if %> </div> <% end_if %>