Have you noticed that we have added a 468×60 rotating banner ads between posts on homepage? You can also create a AdSense ads space between the posts. We have to do a simple template change by adding a few lines PHP codes in the index.php. In this tutorial, we would use WordPress Classic Theme as an example.

1. Open the index.php you may see the WordPress loop that is used to display each of your posts.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php the_date('','<h2>','</h2>'); ?>

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
	 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_tags(__('Tags: '), ', ', ' &#8212; '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>

	<div class="storycontent">
		<?php the_content(__('(more...)')); ?>


<?php comments_template(); // Get wp-comments.php template ?>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

2. Find the following line,

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

then insert the following code above it.

<?php $count = 1; ?>

3. Find the following line,

<?php comments_template(); // Get wp-comments.php template ?>

add the following codes above it.

<?php if ($count == 1) : ?>
<?php endif; $count++; ?>

4. You can display any ads you want just simply replace “YOUR GOOGLE ADSENSE CODES HERE”. $count == 1 means your Adsense ads will be displayed between the first & second post on homepage. So if you want to display the ads on third post, you should edit the number to 3. That’s it!

Do you want to get more tips? Subscribe to our RSS or get updates via daily email, it’s completely free!

Do you like this post?

 Subscribe free via RSS, or by Email to get updates.