简体   繁体   English

Google Adsense没有出现在php循环中

[英]Google adsense doesn't appear in a php loop

I am trying to insert google ads between every 5 posts in my wordpress site with infinite scroll. 我正在尝试无限滚动地在我的wordpress网站的每5个帖子之间插入google广告。

This is the code I am using to add the google ads between every 5 posts 这是我用来在每5个帖子之间添加Google广告的代码

    <?  

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++;

The first ad loads fine in the loop but from the second ad, its just the empty space. 第一个广告在循环中加载良好,但从第二个广告开始,仅加载空白空间。

I am using dfp in my site so more than 3 google ads are allowed in this case. 我在自己的网站上使用了dfp,因此在这种情况下允许使用3个以上的Google广告。

This is the site url : http://bluehandwebdesign.com/dev/hk/ 这是网站网址: http : //bluehandwebdesign.com/dev/hk/

Can you please help me on this? 你能帮我吗?

You should give your id unique identifiers. 您应该为您的ID赋予唯一标识符。 Something like this 像这样

   <? 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++;
  1. Are you also loading the ads in your header? 您是否还在标题中加载广告? as far as I know the dfp api, every ad you include in the content must be mentioned in the site header as well. 据我所知dfp api,您在内容中包含的每个广告也必须在网站标题中提及。 In this case, they will have unique identifiers. 在这种情况下,它们将具有唯一的标识符。
  2. Are you delivering AdSense tags through DFP or use AdSense Fallback for DFP? 您是通过DFP广告管理系统投放AdSense代码还是使用AdSense后备广告DFP广告管理系统? In the first case the max-3-ads rule still applies. 在第一种情况下,max-3-ads规则仍然适用。 In the second case I also wouldn't rely on always having more than 3 ads. 在第二种情况下,我也不会依赖总是拥有3个以上的广告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM