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.

Data Model Questions /

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

show 2° and 3° news in homepage


Go to End


4 Posts   1772 Views

Avatar
bebabeba

Community Member, 193 Posts

9 October 2009 at 4:51am

Hi!

I follow guide to show in my home page the last 3 news. If I want show the second and the third news and not the first how can I modify query?

function LatestNews($num=3) {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

help please..

Avatar
Willr

Forum Moderator, 5523 Posts

9 October 2009 at 12:20pm

Couple ways to do this, best would be to set the offset in the query.

DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", "1,$num");

If you want to don't want to modify that query then you could skip the first in the template as well

<% control LatestNews %>
<% if First %>
<% else %>
 DO STUFF. Will skip the first one
<% end_if %>
<% end_control %>

Avatar
bebabeba

Community Member, 193 Posts

9 October 2009 at 7:49pm

Hi Willr,

thank for your solution!!It's great!! :)

Avatar
fraxter

Community Member, 8 Posts

30 May 2012 at 9:33pm

Hi,

could You help me regarding to showing news on home page... I'd like to get 5 latest news in one box but only one news should be displayed at the same time and news should change every 5 seconds... Could somebody help me how could I receive this goal?

Many thanks in advance
Peter