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.

Archive /

Our old forums are still available as a read-only archive.

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

Displaying first 5 news items from multiple years


Reply


3 Posts   1421 Views

Avatar
Bruce B

Community Member, 147 Posts

14 May 2008 at 7:42pm

The Tutorial has an example that shows the last 5 news items on the front page. However I have grouped my media releases under ArticleHolder pages by year so I can't just use "ParentID = $this->ID" as the filter in the DataObject::get.

I need to say: "Find all the ArticlePages that have the 'Media releases' page at Level(2)".

Does someone have the appropriate syntax for that? Or do I need to provide more context?

cheers
bruce

Avatar
Willr

Forum Moderator, 5513 Posts

14 May 2008 at 11:36pm

So you have 1 article holder for each year?? Then you can get a DataObjectSet of every ArticleHolder then query on each to return the children - or pages with that parent ID as we need to limit it to 5. Remember this is cut down to make it easier to read. I would add an if round the foreach to prevent any errors and you might want to get the ArticleHolders in some order.

$output = new DataObjectSet();
$years = DataObject::get("ArticleHolder");
foreach($years as $year) {
$articles = DataObject::get("ArticlePage","ParentID = $year->ID","","", 5);
$output->push($articles);
}
return $output;

Avatar
Bruce B

Community Member, 147 Posts

15 May 2008 at 12:17pm

Looking at that code, it would seem to pull 5 news items from each year, rather than 5 in total. I have attacked it from a different point, creating a new page type called NewsPage, which is just a duplicate of ArticlePage. Now I can pull the most recent media releases, where ever they are, using:
function LimitedNews($limit) {
$littlechildren = DataObject::get("NewsPage", "", "Date DESC", null, $limit);
return $littlechildren;
}

cheers
bruce