Insert google dfp ads between every 5 posts using infinite scroll plugin
-
Hi,
I am having a wordpress site in which the frontpage posts are loaded using infinite scroll plugin https://ww.wp.xz.cn/plugins/infinite-scroll/ The page will have 8 ads and Now i am trying to insert google dfp ads between every 5 posts. I got the main loop to work but the real issue is that i have to run an other counter to increment the google ads ID. Hence the first counter will insert the ads every 5 posts, and the next counter will increment the google ads id by 1 every time the loop is executed.
‘$count=0; $counter=0;
if (($count>4) && ($count%5==0)){
$counter= $counter+1;
?>
<div id=”adsbetween”>
<div id=’div-gpt-ad-xxxx-<?php echo $counter; ?>’ 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 $counter; ?>’); });
</script>
</div>
</div>
<?php
}$count++;’In the above code, the same ad is inserted every time hence the ad doesn’t load. can you help me getting the counter value to increment by 1 each time?
The topic ‘Insert google dfp ads between every 5 posts using infinite scroll plugin’ is closed to new replies.