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.

Data Model Questions /

show 2° and 3° news in homepage


Reply


4 Posts   1151 Views

Avatar
bebabeba

Community Member, 192 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, 5513 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, 192 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