I am trying to insert google ads between every 5 posts in my wordpress site with infinite scroll.
This is the code I am using to add the google ads between every 5 posts
<?
if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post();
//before
if (($count>1) && ($count%5 == 0) ){
?>
<!-- AD_HP_RC-2 -->
<div id="adsbetween">
<div id='div-gpt-ad-xxxx-0' style="width:300px; height:450px; display:inline-block; float:right;">
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxx-0'); });
</script>
</div>
</div>
<?
}
$count++;
The first ad loads fine in the loop but from the second ad, its just the empty space.
I am using dfp in my site so more than 3 google ads are allowed in this case.
This is the site url : http://bluehandwebdesign.com/dev/hk/
Can you please help me on this?
You should give your id unique identifiers. Something like this
<? if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post();
//before
if (($count>1) && ($count%5 == 0) ){
?>
<!-- AD_HP_RC-2 -->
<div id="adsbetween">
<div id='div-gpt-ad-xxxx-<?php echo $count; ?>' style="width:300px; height:450px; display:inline-block; float:right;">
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxx-<?php echo $count; ?>'); });
</script>
</div>
</div>
<?
}
$count++;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.