首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个Google广告根据条件动态发布

多个Google广告根据条件动态发布
EN

Stack Overflow用户
提问于 2014-03-07 13:31:50
回答 1查看 107关注 0票数 1

我正在用Yii实现我的项目,我正在给Google ads打电话。它正在显示,但应根据条件显示。

我从数据库中动态调用数据,并使用内容调用图像。在一个广告应该显示之后,将显示10个类别食谱,但只有在该广告显示为空白之后才显示一次。

我在这里写了我的代码,请建议我如何修复这个代码。我想每十个类别,一个谷歌广告将被显示。

代码语言:javascript
复制
<?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 } ?>
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 16:32:39

试试下面这样的方法。要点:

  • 我已经使用Modulus Operator - %计算出您何时在第10项上。
  • 假设您的$posts数组是0索引的连续数组,我已经剥离了所有的$counter变量-您只需要在foreach循环中的$k <代码>H29<代码>H110我在<代码>H212<代码>F213中添加了一个缺少结束标记的<代码>D11

希望这能对你有所帮助:

代码语言:javascript
复制
// $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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22242304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档