在 index.php 文件,找到这一行: <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
显然这是 WP 主循环的起点。
在前面增加下代码:
<?php $counter = 0; ?>
之后增加:
<?php $counter = $counter + 1;?>
再接着就是如下的代码:
<?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
至少,你会看到 这个语句。
在这之前,添加以下代码:
<?php if(1 == $counter) : ?> "ad code" <?php endif; ?> <?php if(3 == $counter) : ?> "ad code" <?php endif; ?>