Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » nextSibling

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

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

Page: 1
Go to End
Author Topic: 2453 Views
  • Richie
    Avatar
    Community Member
    18 Posts

    nextSibling Link to this post

    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!

  • jam13
    Avatar
    121 Posts

    Re: nextSibling Link to this post

    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.

  • Richie
    Avatar
    Community Member
    18 Posts

    Re: nextSibling Link to this post

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

    2453 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.