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.

Template Questions /

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

Latest News show all in News section


Go to End


2 Posts   1763 Views

Avatar
clschnei

Community Member, 2 Posts

29 September 2010 at 5:35am

I am using and Article Holder to show the latest news for a website, but I only wish to show the first three. Right now it is showing every article in the News section.

Is there anyway to only show the first 3?

Avatar
3dgoo

Community Member, 135 Posts

29 September 2010 at 2:42pm

http://doc.silverstripe.org/tutorial:2-extending-a-basic-site#showing_the_latest_news_on_the_homepage

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

<% control LatestNews %>
    $Content
<% end_control %>