17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1279 Views |
-
Displaying first 5 news items from multiple years

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 -
Re: Displaying first 5 news items from multiple years

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; -
Re: Displaying first 5 news items from multiple years

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
| 1279 Views | ||
|
Page:
1
|
Go to Top |


