Hi everybody!
Is there a way to get all the pages from 2 different categories or sections? Something like that?
<?php foreach(page('projects')->children()->visible() as $project || page('blog')->children()->visible() as $news): ?>
I want to show in a page all the projects resume and some news between them.
Is it posible?
Thank you very much!
Quick shot - not tested, but it’s in the docs (http://getkirby.com/docs/cheatsheet/site/find):
$site->find('projects','news')->children()->visible()
I think that should give you all of them combined.
UPDATE: and to sort them e.g. after a date field or so use ->sortBy() http://getkirby.com/docs/cheatsheet/pages/sortBy
3 Likes
How are you wanting to arrange them?
For example, if you want one project followed by two news items:
<?php
$news = page('blog')->children()->visible()->first();
foreach(page('projects')->children()->visible() as $project) :
?>
<div class="project">
<h1><?php echo $project->title() ?></h1>
// Other project stuff
</div>
<?php if($news) : ?>
<div class="news">
// News stuff
</div>
<?php endif; ?>
<?php
if($news->hasNextVisible())
$news = $news->nextVisible();
else
$news = null;
?>
<?php endforeach; ?>
1 Like
find() returns a $pages collection and $pages->children() returns “a $pages collection with all children of each page in the collection.” (to quote the cheatsheet) - so I think this will work, and could be the most elegant solution!
Very interesting! I’m going to try it!
Thank you very much :))))
In a happy world they should arrange by date, but that can be a second iteration 
Anyway is nice approach too! I will try it to see how it works.
Thank you very much!
You can simply add ->sortBy('date')->flip()
to order them by date
1 Like