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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

nextSibling


Go to End


3 Posts   4194 Views

Avatar
Richie

Community Member, 18 Posts

7 December 2008 at 10:42pm

Is there a function/method to add a link to the next sibling inside a page? For example for portfolio pages to add a 'go to next project' link. Thanks!

Avatar
jam13

121 Posts

8 December 2008 at 3:41am

There's no built in function for this that I know of, but it's fairly easy to add to your Page controller:

  function NextSibling() {
    $pages = DataObject::get("SiteTree", "ParentID = {$this->ParentID} AND Sort > {$this->Sort}", "Sort", "", 1);
    if($pages) return $pages->First();
  }
  function PreviousSibling() {
    $pages = DataObject::get("SiteTree", "ParentID = {$this->ParentID} AND Sort < {$this->Sort}", "Sort DESC", "", 1);
    if($pages) return $pages->First();
  }

This is most efficient way I could find of doing it anyway.

Avatar
Richie

Community Member, 18 Posts

8 December 2008 at 10:32pm

Thank you for this! And for pointing out the use of a query in this situation.