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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Next and Previous page links


Reply


2 Posts   841 Views

Avatar
mattupstate

Community Member, 12 Posts

5 August 2011 at 3:57am

Say I have a "ProjectsHolder" page type, and its children are only of type "ProjectPage". From within "ProjectPage" is there an easy way to get the next and previous pages from the children of "ProjectsHolder" ?

Avatar
MarcusDalgren

Community Member, 288 Posts

5 August 2011 at 5:31am

If you know what you're ordering them by then yes. Not sure exactly how you want to do it but if you're using the Sort column from SiteTree then you can write your own function in ProjectPage that fetches the next page in the sequence.

For example

function NextProject() {
   return DataObject::get_one("ProjectPage", "Sort = ".($this->Sort+1));
}

Now if you have several project holders you need to add the ParentId as well but that should be the gist of it. In the template for a ProjectPage you can now write NextProject.Link to get the page link.