RSS feed for multiple sections

I am using @bastianallgeier’s RSS Feed Plugin. It works really great for feeds from separate sections (in my case: blog and tutorials). In addition I would like to offer one feed to rule them all. Is it possible to fetch entries from multiple sections?

Instead of

echo page('blog')->children()->visible()->flip()->limit(10)->feed(array(…));

I would like to get all children objects of blog and tutorials. I already looked through the Cheatsheet but couldn’t find a proper solution.

Untested but this…

echo page('blog', 'tutorials')->children()->visible()->flip()->limit(10)->feed()

…should work.

I’m afraid not. :confused:

Only blog entries are getting fettched.

Ah, shit, page() is not properly fetching them into a pages collection. This works:

echo $site->find('blog', 'tutorials')->children()->visible()->flip()->limit(10)->feed()
1 Like

Awesome! That works perfectly. Thanks Bastian! :smile:

I just noticed something odd…

I had to swap flip() with sortBy('date', 'desc'):

echo $site->find('blog', 'tutorials')->children()->visible()->sortBy('date', 'desc')->limit(10)->feed()

Otherwise only the last 10 tutorials would be fetched when limit < total count of blog posts and tutorials.

And…

Another issue:

To stay DRY there should only be one flexible feed template and the page section should be set via a section data field. It works perfectly for blog (section: blog) or tutorials (section: tutorials) but not for both (section: blog, tutorials). I also tried section: 'blog', 'tutorials' and played with Kirby field methods in the template.

Content file for full feed:

Title: Blog and Tutorials

----

Description:

----

section: blog, tutorials

----

link: 

Feed template:

<?php

echo $site->find($page->section())->children()->visible()->sortBy('date', 'desc')->limit(10)->feed(array(
  'title'       => $page->title(),
  'description' => $page->description(),
  'link'        => $page->link()
));

?>

Any idea?

Seriously untested, but:

$roots = call_user_func_array(array($site, "find"), $page->section()->split());
echo $roots->children()->visible()->sortBy('date', 'desc')->limit(10)->feed(array(
  'title'       => $page->title(),
  'description' => $page->description(),
  'link'        => $page->link()
));
1 Like

Thanks @walkerbox, that works great! :smiley: