【问题标题】:Google adsense doesn't appear in a php loopGoogle adsense 没有出现在 php 循环中
【发布时间】:2014-10-06 20:19:31
【问题描述】:

我正在尝试在我的 wordpress 网站的每 5 个帖子之间插入谷歌广告,并无限滚动。

这是我用来在每 5 个帖子之间添加谷歌广告的代码

    <?  

if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post();

    //before 

    if (($count>1) && ($count%5 == 0) ){ 
    ?>

<!-- AD_HP_RC-2 -->
<div id="adsbetween">
<div id='div-gpt-ad-xxxx-0' style="width:300px; height:450px; display:inline-block;       float:right;">
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxx-0'); });
</script>
</div>
</div>
    <?

    }

    $count++;

第一个广告在循环中加载正常,但从第二个广告开始,它只是空白。

我在我的网站中使用 dfp,因此在这种情况下允许超过 3 个谷歌广告。

这是网站网址:http://bluehandwebdesign.com/dev/hk/

你能帮我解决这个问题吗?

【问题讨论】:

    标签: javascript php wordpress adsense


    【解决方案1】:

    您应该为您的 id 提供唯一标识符。像这样的

       <? if ( have_posts() ) : $count = 0; while ( have_posts() ) : the_post();
    
        //before 
    
        if (($count>1) && ($count%5 == 0) ){ 
        ?>
    
    <!-- AD_HP_RC-2 -->
    <div id="adsbetween">
    <div id='div-gpt-ad-xxxx-<?php echo $count; ?>' 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 $count; ?>'); });
    </script>
    </div>
    </div>
        <?
    
        }
    
        $count++;
    

    【讨论】:

    • 也。尽量不要使用简短的php标签
    【解决方案2】:
    1. 您是否也在标题中加载广告?据我所知 dfp api,您在内容中包含的每个广告也必须在网站标题中提及。在这种情况下,它们将具有唯一标识符。
    2. 您是通过 DFP 投放 AdSense 代码还是使用 AdSense Fallback for DFP?在第一种情况下,max-3-ads 规则仍然适用。在第二种情况下,我也不会总是依赖 3 个以上的广告。

    【讨论】:

      猜你喜欢
      • 2022-12-03
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多