[英]Issue with Yii infinite scroll and Google AdSense
我已经在Yii框架中实施了该项目。 我在使用Google广告和Yii无限滚动(即延迟加载)时遇到了问题。 我有问题。 我将代码从站点控制器发送到索引页面,以进行无限滚动,页面大小为10。我想在页面中展示Google广告5。 我的索引页面包含配方细节,即带有细节的图像。 我希望每10张图片向Google显示一次广告。 如果删除控制器代码(即发送页面大小代码)。 五个Google广告运行正常。 问题是我的索引页是容器大的,即可能超过300张图像。 这样我就可以使用无限滚动显示这10 x 10。
我在这里添加了代码; 请建议我如何克服这个问题:
我的控制器代码是:
$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,
));
我的索引页面是:
<?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++;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.