Adsense inline your Wordpress Blog posts
By Jamsi • Mar 7th, 2006 • Category: PHPI stumbled upon this very handy guide on how to insert an adsense ad unit after the first post on your wordpress blog.
To do this you will need to be able to edit the template files, specifically the “index.php” file.
The guide uses a simple PHP if statement to count the number of posts and insert the adsense code after the first post (or second or third etc).
Open up the template file index.php in your favourite text editor and add this to the top.
1 2 3 4 | <?php $postnum = 1; $showadsense1 = 1; ?> |
In the index file there is a “while” loop that grabs all the needed wordpress posts.
It starts with this
1 | <?php if (have_posts()) : while (have_posts()) : the_post(); ?> |
and ends with
1 | <?php endwhile; ?> |
Just before this “endwhile” statement, we need to add some code.
1 2 3 4 5 6 | <?php if ($postnum == $showadsense1) { echo 'Your adsense code goes here'; } $postnum++; ?> |
And your done!
Read more about tips on adding Adsense to your blog.
No related posts.
FREE NEWSLETTER -> Want Tech Tips Sent Straight to your Inbox?
Grab our Newsletter to Ensure your PC is Running Smooth!
Jamsi is currently studying a full time Bachelor of Computer/Business degree and working part time as an Internet Security Consultant.
Email this author | All posts by Jamsi























