I am using the controller on my front page to call 2 WP_Query for 2 different post types:
<?php
namespace App\Controllers;
use Sober\Controller\Controller;
use WP_Query;
class FrontPage extends Controller
{
public function get_latest() {
$work_args = array(
'post_type' => 'work',
'posts_per_page' => 3,
);
$get_latest['work'] = new WP_Query( $work_args );
$post_args = array(
'post_type' => 'post',
'posts_per_page' => 2,
);
$get_latest['posts'] = new WP_Query( $post_args );
return $get_latest;
}
}
I then call them like this i the blade template for the front-page:
@if( $get_latest['work']->have_posts() )
<section id="latest-work">
<h2>Latest Work</h2>
@while ( $get_latest['work']->have_posts()) @php $get_latest['work']->the_post() @endphp
@include('partials.content-work')
@endwhile @php(wp_reset_postdata())
<div class="dots">
<a href="{{ home_url('/work/') }}" class="btn">View all work</a>
</div>
</section>
@endif
@if( $get_latest['posts']->have_posts() )
<section id="latest-posts">
<h2>Latest Blog Posts</h2>
@while ( $get_latest['posts']->have_posts()) @php $get_latest['posts']->the_post() @endphp
@include('partials.content-blog')
@endwhile @php(wp_reset_postdata())
<div class="dots">
<a href="{{ home_url('/blog/') }}" class="btn">View all posts</a>
</div>
</section>
@endif
but all I get is an error saying unexpected endwhile
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: syntax error,
unexpected 'endwhile'
Can anyone shed any light on why this is happening? I’m fairly new to both Sage and Blade templating.