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.

Template Questions /

forward button - sitetree, not history


3 Posts   1495 Views

wilhelm oder wil er nicht

Community Member, 16 Posts

20 February 2009 at 2:33am

hi there

I got a wee simple site to create which has got a special navigation: it doesn't have a menu, there are only buttons which you can use for forward and backwards, it should follow the arrangement of the site tree, not the browser history, can you follow me? let's say it's like a little story. I would love to post something into the template and not to link every single button in the cms.
any inputs?


Community Member, 787 Posts

22 February 2009 at 3:12am

You can use the $Sort property to obtain the current position of your page in the sortorder ...

You can then build your previous and next links by getting pages based on their sortorder (currentSort +1 and currentSort -1) ...

Good luck !


Community Member, 55 Posts

6 April 2009 at 10:00pm

I wanted this too - here's my solution to it.

In the Page_Controller class I have:

   function NextSibling() {
      return DataObject::get_one('SiteTree', "ParentID=$this->ParentID and Sort > $this->Sort and Status='Published' and ShowInMenus=1", false, 'Sort asc');

   function PrevSibling() {
      return DataObject::get_one('SiteTree', "ParentID=$this->ParentID and Sort < $this->Sort and Status='Published' and ShowInMenus=1", false, 'Sort desc');

and in the template I have:

<div id="NextPrev">
<% if PrevSibling %>
   <a href="$PrevSibling.Link">&laquo; Previous Page</a>
<% end_if %>

<% if NextSibling && PrevSibling %> | <% end_if %>

<% if NextSibling %>
   <a href="$NextSibling.Link">Next Page &raquo;</a>
<% end_if %>

I don't know if this is the best way to do it, but it works for me.