Forum

Thread tagged as: Question, Runway, Blog

2 Blogs – Show posts from 1 of those blogs every 'x' number of posts from other...

I have 2 blogs:

  1. News
  2. Reports

I'm working on a layout that renders a list of News in date order, but every 2 News posts I need to render a Report. The Reports themselves need to be in date order, but not in the context of the news posts.

eg.

  • News Post [May 2017]
  • News Post [May 2017]
  • Report [Feb 2017]
  • News Post [Apr 2017]
  • News Post [Mar 2017]
  • Report [Dec 2016]
  • News Post [Feb 2017]
  • News Post [Jan 2017]
  • Report [Nov 2016]

Do you think this be can achieved directly via templates or do you think I need to be using a callback on perch_blog_custom

Toby Martin

Toby Martin 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't do that directly with templates, no. The idea of multiple blogs is that they're silos.

Think I've nailed it:


$blogData = perch_blog_custom([ 'skip-template' => true, 'blog' => 'blog' ]); $reportData = perch_blog_custom([ 'skip-template' => true, 'blog' => 'reports' ]); $blogCounter = 0; $reportCounter = 1; foreach ($blogData as $post) { $blogCounter++; perch_blog_custom([ 'blog' => 'blog', 'filter' => 'postSlug', 'match' => 'eq', 'value' => $post['postSlug'], 'template' => '_insights.html' ]); if ($blogCounter % 2 === 0 ) { perch_blog_custom([ 'blog' => 'reports', 'paginate' => false, 'count' => 1, 'start' => $reportCounter, 'template' => '_report_in_list.html', ]); $reportCounter++; } }