php - Inserting ads into Jetpack infinite scroll loop -


i creating infinite scrolling blog , ads shown every 5 posts. code 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 on , no longer shows ads @ all. i'm wondering if there way can continue show ads though after 7 posts jetpack takes reigns.

instead of having 2 different template parts, try adding 'content' template.

like so:

if ($i < 4) {     // actual post //     $i++; } if($i == 5) {  // ad code //         $i=0; } 

that way should part infinite scroll output. have not tested though can not 100%


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -