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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

link to next and previous item


Go to End


1407 Views

Avatar
JMagnusson

Community Member, 29 Posts

2 April 2011 at 4:52am

Edited: 02/04/2011 10:42pm

Hi
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)?

Edit:
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.
/Thanks

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?