Jump to:

1856 Posts in 1610 Topics by 562 members

Blog Module

SilverStripe Forums » Blog Module » Can I offset a Latest posts Called on the home page

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1136 Views
  • Musicaldustbin
    Avatar
    Community Member
    13 Posts

    Can I offset a Latest posts Called on the home page Link to this post

    Hi people i have pulled latest blog posts on my manin page but wondered if i could offset the <% control LatestNews(1) %> call so I could have the 2 post in an alternate layout

    Im new be nice

    Any help would really make my day thanks heaps

    Nick

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Can I offset a Latest posts Called on the home page Link to this post

    You can try having a 'limit' and an offset. ie

    <% control LatestNews(1, 1) %>

    Then in your function you would have

    function LatestNews($num=5, $offset=0) {
    $news = DataObject::get_one("ArticleHolder");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", "{$offset,$num}") : false;
    }

    I'm pretty sure passing 2 arguments to a function works. If not then you may need to get rid of the 'limit' one and use it for offset (since you aren't changing the limit).

  • Musicaldustbin
    Avatar
    Community Member
    13 Posts

    Re: Can I offset a Latest posts Called on the home page Link to this post

    Thanks for the help it exactly what i was looking for !!!

    Silverstripe certainly turning out to be a great platform

    i did however have to remove the {} as i was getting a syntax error but now seems to be working fine

    function LatestNews($num=5, $offset=0) {
    $news = DataObject::get_one("ArticleHolder");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", "$offset,$num") : false;
    }

    Thank you so much for you help and saving me a massive headache

    Cheers
    Nick

    1136 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.