5329 Posts in 1601 Topics by 1169 members
|Go to End|
2 April 2011 at 4:52am Last edited: 2 April 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 ProductPage.ss 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?
|Go to Top|