3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 316 Views |
-
[SOLVED] Multiple News

21 October 2011 at 8:02am Last edited: 24 October 2011 5:56am
Hi,
I try to do multiple news consisting of News, "NewsPage" and the news "DiscographyNews".I would like to be displayed by date.
At the moment I found such a thingfunction LatestNews($num=10) {
return DataObject::get("ArticlePage", "", "Date DESC", "", $num);
}Everything is good because it displays each note of the layout Articlepage (anywhere I would not put it)
When I try insert this code:function LatestNews($num=10) {
return DataObject::get("DiscographyPage", "", "Date DESC", "", $num);
}displays all DiscographyPage
I would like to combine it into one to sort by date and display all at once on the home page
I tried this:
function LatestNews($num=10) {
return DataObject::get("ArticlePage", "", "Date DESC", "", $num);
return DataObject::get("DiscographyPage", "", "Date DESC", "", $num);
}But then retrieves only the first "return".
It can be somehow unite?
I find that but this not sort by date
function LatestNews($num=15) {
$articles = DataObject::get("ArticlePage", "", "Date DESC", "", $num);
$disc = DataObject::get("DiscographyPage", "", "Date DESC", "", $num);$articles->merge($disc);
return $articles->getRange(0, $num);
}
Struck-out text because: See post belowSorry for my bad English
-
Re: [SOLVED] Multiple News

24 October 2011 at 5:53am
I answer myself but it may be useful to someone.
I found a solution.
In function LatestNews need to insert such a thingfunction LatestNews($num=15) {
$sorcik = new DataObjectSet();
$sorcik->merge(DataObject::get("ArticlePage", "", "Date DESC", "", $num));
$sorcik->merge(DataObject::get("DiscographyPage", "", "Date DESC", "", $num));
$sorcik->merge(DataObject::get("BiographyPage", "", "Date DESC", "", $num));
$sorcik->sort('Date', 'DESC');
return $sorcik->getRange(0, $num);
}Now function LatestNews collects all the news of the code pages (in my case: ArticlePage, DiscographyPage and BiographyPage) and sorts them by date.
Sorry for my bad English
| 316 Views | ||
|
Page:
1
|
Go to Top |

