I have implemented the project in Yii framework. I have issue with Google ads and Yii infinite scroll ie (lazy loading). I have problem with it. I sending the code from site controller to index page for infinite scroll which page size is 10. I want to be show the Google ads 5 in a page. My index page contains recipe details i.e. image with details. I want to be show the Google ads every 10 images one ad should be displayed. If I remove the controller code (i.e. I sending the page size code). Five Google ads are working fine. The issue is my index page is container large size, i.e. it could be more than 300 images. so that I showing these 10 by 10 using infinite scroll.
I added my code here; please suggest my how to overcome this issue:
My controller code is:
$criteria = new CDbCriteria;
$total = Recipe::model()->count();
$pages = new CPagination($total);
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$posts = Recipe::model()->findAll($criteria);
$this->render('index', array(
'posts' => $posts,
'pages' => $pages,
));
My index page is:
<?php $post_counter=0; $addnum=1; foreach($posts as $receipe): ?>
<div class="post">
<?php
$rec_img=$receipe['recipe_small_image'];
$recipe_id=$receipe['recipe_id'];
$rec_name=$receipe['name'];
$calorie_count=$receipe['calorie_count'];
$type=$receipe['type'];
$rec_course=$receipe['course_id'];
$cus_name=$receipe['cuisinename'];
$post_counter++;
if(($post_counter=9 && $addnum<=4)) {
$post_counter=1;
?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-11 wrdLatest" id="imgcontent_rand_recipe">
<script async src="xxxxxxxxxxxxx"></script>
<ins class="adsbygoogle kraftmonsterresponsive"
style="display:xxxxxxxxxx"
data-ad-client="xxxxxxxxxx"
data-ad-slot="xxxxxxxxxxx"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
<?php }
$addnum= $addnum+1;
$post_counter++;
?>