I would like to insert AdSense Code inside my wordpress loop after 3, 5, 10 posts. this is my code:
<?php
if ( have_posts() ) : ?>
<?php
while ( have_posts() ) : the_post();
get_template_part('/framework/templates/content-grid', get_post_format());
endwhile;
else :
get_template_part( '/framework/templates/content', 'none' );
endif; ?>
How could I manage this?
You can achieve this by creating a custom counter.
<?php
$i = 1;
if ( have_posts() ) : ?>
<?php
while ( have_posts() ) : the_post();
if($i==3||$i==5||$i==10){
/*Adsence here*/
}
get_template_part( '/framework/templates/content-grid', get_post_format() );
$i++;
endwhile;
else :
get_template_part( '/framework/templates/content', 'none' );
endif; ?>