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