7881 Posts in 2037 Topics by 1136 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 | go to end | Reply | |
| Author | Topic: Displaying first 5 news items from multiple years | 304 views |

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

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;

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
| 304 views | |||
| go to top | Reply |