While there are many posted solutions on how to insert custom components between posts, I haven't been able to find one that addresses pagination. Currently, on my Wordpress archive template, each page shows 12 posts.
While I'm able to insert a custom component after the 2nd post, given the example below, if I also want to add an additional component that is specified after the 13th post, it will never appear since WP starts the count over again. In addition, the same component is returned on every page.
I assume I need to know the total number of pages in advance so there's a number to check against?
Currently:
@extends('layouts.app')
@section('content')
@include('partials.page-header')
@php
$global = $wp_query;
$count = 1;
// get total pages?
$total_pages = $wp_query->max_num_pages;
@endphp
@if (!have_posts())
{{ __('Sorry, there are no posts.', 'sage') }}
{!! get_search_form(false) !!}
@endif
@while (have_posts()) @php the_post() @endphp
@include('partials.content-'.get_post_type())
@if ($count == 2 )
@include('partials.component_1')
@endif
@if ($count == 13 )
@include('partials.component_2')
@endif
@php $count++ @endphp
@endwhile
{!! pagination_bar() !!}
@endsection
@
syntax in your code?