Pages Menu
TwitterRssFacebook
Categories Menu

Posted by on May 30, 2013 in Wordpress | 0 comments

Display adsense or any add after first post

A very simple solution which may have a good overall effect on your CTR is to display your google adsense, or any other advertising you are using on your wordpress blog / website is to display the add after the first post in the wordpress loop.

It can be achieved by adding a loopcounter to the loop.

How to insert adsense adds after the first post?

At first, you will have to locate the WordPress loop most probably in your index.php file of the template you are using. Optionally that can be any loop located in your theme’s template files ( home.php , category.php or custom loops )

Locate the loop, it will look like this:

01.<?php if (have_posts()) : ?>
02.
03.<?php while (have_posts()) : the_post(); ?>
04.
05.// the loop stuffs
06.
07.<?php endwhile; ?>
08.
09.<?php else : ?>
10.
11.<?php endif; ?>

Now, create a file named add.php or adsense.php (you can use any name you want) and place the add code inside of it.

We should now add the loopcounter in the wordpress loop to display our add after the first post.

01.<?php if (have_posts()) : ?>
02.
03.<?php while (have_posts()) : the_post(); $loopcounter++; ?>
04.
05.// the loop stuffs
06.
07.<?php if ($loopcounter <= 1) { include (TEMPLATEPATH . '/add.php'); } ?>
08.
09.<?php endwhile; ?>
10.
11.<?php else : ?>
12.
13.<?php endif; ?>

That’s it. Now your add will appear after the first post.

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>