我正在用Yii实现我的项目,我正在给Google ads打电话。它正在显示,但应根据条件显示。
我从数据库中动态调用数据,并使用内容调用图像。在一个广告应该显示之后,将显示10个类别食谱,但只有在该广告显示为空白之后才显示一次。
我在这里写了我的代码,请建议我如何修复这个代码。我想每十个类别,一个谷歌广告将被显示。
<?php $counter=0; $count123=0; ($posts as $receipe):?> <div class="post">
<?php $counter=$counter+1;
if($count123<4 && $counter==9)
{ ?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-11 wrdLatest" id="imgcontent_rand_recipe">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" id="kraftmonsterresponsive"
style="display:block"
data-ad-client="xxxxxxxxxxx"
data-ad-slot="xxxxxxxxxxxxxxxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php
$counter=1;
$count123=$count123+1; ?> </div>
<?php } ?>发布于 2014-03-07 16:32:39
试试下面这样的方法。要点:
%计算出您何时在第10项上。$posts数组是0索引的连续数组,我已经剥离了所有的$counter变量-您只需要在foreach循环中的$k <代码>H29<代码>H110我在<代码>H212<代码>F213中添加了一个缺少结束标记的<代码>D11希望这能对你有所帮助:
// $k is 0 indexed
foreach($posts as $k => $receipe)
{
?>
<div class="post">
<?php
// Print your Post or recipe info here
print_r($receipe);
// Now check for each 10th item
if((($k + 1) % 10) == 0)
{
?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-11 wrdLatest">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" id="kraftmonsterresponsive" style="display:block" data-ad-client="ca-pub-1823432637478832" data-ad-slot="3981469793" data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<?php
}
?>
</div><!-- .post -->
<?php
}https://stackoverflow.com/questions/22242304
复制相似问题