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.

Customising the CMS /

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

link to next and previous item

Go to End



Community Member, 29 Posts

2 April 2011 at 4:52am

Edited: 02/04/2011 10:42pm

I have products as DataObjects. How can I write a link to next and previous product (ordered by Title, and the first one have either a blank previous link or is linked to the last product, the URL-column named URLSegment)?

Now I know where to put the code. It is published using renderwith like this:


$NextProduct = DataObject::get("product",'','Title ASC', "", 1);

$Data = array(
'Product' => $Product,
'NextProduct' => $NextProduct,

//return our $Data array to use, rendering with the template
return $this->customise($Data)->renderWith(array('ProductPage', 'Page'));


This works, but picks the first item in the product table, not the next. I need some kind of WHERE clause, I think.

Edit #2: This worked:
$Where = "Title BETWEEN '" .$Product->Title ."z' AND 'Zzz' ";

But the query pick items from all the categories, so I need to write something more.
Unfortunately the categories is given in another table `categorypage_products` with CategoryPageID and ProductID. Do I have to use a subquery?