I am creating an infinite scrolling blog and would like ads to be shown every 5 posts. My code is as shown:
<?php
while (have_posts()) : the_post();
if ($i < 4) {
get_template_part( 'content', get_post_format() );
$i++;
} elseif ($i == 4) {
get_template_part( 'ad_template', get_post_format() );
$i=0;
}
endwhile;
?>
This works fine until Jetpack's infinite scrolling takes over and no longer shows the ads at all. I'm wondering if there is a way I can continue to show ads even though after 7 posts Jetpack takes the reigns.
Instead of having two different template parts, try adding that into the 'content' template.
Like so:
That way it should be a part the infinite scroll output. I have not tested this though so can not be 100%