Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » link to next and previous item

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

Page: 1
Go to End
Author Topic: 857 Views
  • JMagnusson
    Community Member
    29 Posts

    link to next and previous item Link to this post

    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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.