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.

Blog Module /

Discuss the Blog Module.

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

Can I offset a Latest posts Called on the home page


Go to End


3 Posts   1724 Views

Avatar
Musicaldustbin

Community Member, 13 Posts

17 February 2011 at 6:57pm

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 :P

Any help would really make my day thanks heaps

Nick

Avatar
Willr

Forum Moderator, 5523 Posts

18 February 2011 at 12:19pm

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

Avatar
Musicaldustbin

Community Member, 13 Posts

18 February 2011 at 1:50pm

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