我想在我的帖子列表中每十个帖子放置一个adsense正方形(250x250)广告。
我尝试将此代码添加到我的索引.php,在帖子div 内:
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 11) : ?>
Ad code is here
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php else : ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
它正确显示,但由于某种原因,帖子的所有格式都发生了变化。
另外,此代码仅在第十个帖子之后放置一个广告,并且在第二十个帖子之后不会自动重复,依此类推。
这实际上并不重要,我可以重复这些数字。
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
//////////////////////
<?php if($count%10==0){ echo "</br></br></br>"; } ?>
///////////////////
<?php if ($count == 11) : ?>
Ad code is here
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php else : ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>