Jump to:

5537 Posts in 1737 Topics by 1223 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: 852 Views
  • JMagnusson
    Avatar
    Community Member
    29 Posts

    link to next and previous item Link to this post

    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?

    852 Views
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.