How to display two contents mixed

Hey there!
I’ve got two contents in my project, news and events.
This two contents have some similar fields (title, date, description) and others personal.

I would like to display a list of the two contents mixed and sorted by date, like that:

21/10/2016 - event 1
20/10/2016 - event 2
19/10/2016 - news 1
17/10/2016 - event 3
15/10/2016 - news 2
....

How can I do that?

Thanks!

I assume both events and news are children of projects? Then it’s pretty straightforward:

<?php
foreach(page('projects')->children()->visible()->sortBy('date', 'desc') as $project) {
  // do stuff
}
?>

Otherwise, I need some more input how your content is organized.

Actually I omitted an important info :sweat:: “news” and “events” are in the root content folder, so they are not the only children.

Yes, I can move them into a new “editorial” folder and use your solution or is there another one?

Thanks

Yes, there is an alternative, you can merge the two collections:

<?php 
  $news = page('news')->children()->visible();
  $events = page('events')->children()->visible();
  $mixed = new Pages(array($news, $events))->sortBy('date', 'desc');
?>
3 Likes

Perfect! :grinning:

Thanks!