In my wordpress home.php file, I have placed an increment loop with the help of a few stackexchange threads:
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>
<?php if (function_exists ('adinserter')) echo adinserter (1); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php $count = 0; ?>
<?php else : ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Where, inside the content.php file, I have the following:
<div class="row">
<div class="col-md-3">
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail('my_feature_image', array( 'class' => "img-responsive" ));
echo '</a>';
}
?>
</div>
<div class="col-md-9">
<h3 class="article-list-header"><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong></h3>
<h4 class="article-list-subheader"><?php the_time('l, F jS, Y'); ?></h4>
<p><?php the_content(); ?></p>
</div>
</div>
As you can see above, I have tried to place this: <?php if (function_exists ('adinserter')) echo adinserter (1); ?>
after every three posts which doesn't seem to work no matter what value I add to the count. It echo the php function at random positions and it also doesn't seem to work on the next page of my infinite scroll homepage.
Can I please get some pointers on what I'm doing wrong here.
<?php if (function_exists ('adinserter')) echo adinserter (1); ?>