How To: Display Adsense On Your First Post Within The Loop
June 7, 2008 by Tony · Leave a Comment
In this guide you’ll learn how to display Adsense on just your first post within the Loop. Sure, there may be plugins that will do this for you. This guide, however, will use code examples to accomplish the same thing by editing your WordPress theme.
The first step is to open up your index.php file in your theme editor. Find the following line:
<?php if(have_posts()) : ?>
Just above that, insert the following like this:
<?php $i = 1; ?>
<?php if(have_posts()) : ?>
Now, scroll down a bit until you find this line:
<?php endwhile; ?>
Insert the following above it, like so:
<?php $i++; ?>
<?php endwhile; ?>
The final step is to insert your Adsense code. Locate where exactly you’d like it within the Loop, and place it between a conditional tag like this:
<?php if ($i == 1) { ?> [YOUR ADSENSE CODE HERE] <?php } ?>
And that’s all you have to do. You can be creative with this code as well. You could add a certain css style class to the top post in your Loop. It doesn’t even have to be the first either, as you can just change the number in $i == 1 to whatever you want. This same method can be used in other archive templates such as archive.php.
Ultimate Guide to the WordPress Loop
June 7, 2008 by Tony · Leave a Comment
One of my favorite parts about using WordPress for my blogs is getting to work with PHP code, which I find to be much easier to write/hack. For those that are shy around code, it really isn’t that difficult to get ahold of the basics of PHP, so WordPress is the right place for you.
One great area to start is learning how the WordPress loop works. This is a basic function of blogging used to display the most recent X number of posts on your blog’s homepage (for traditional blogs). Rather than go into to much detail here, I’d like to point you towards a new post by Themelab which is designed to be the Utlimate Guide to the WordPress loop.
This post definitely lives up to its name and goes beyond just showing you how to do something. It actually explains how and why it works, and includes screenshots with many of the examples. If you have any interest in learning about the WordPress loop you may want to read through this post and/or bookmark it for future reference.
WordPress Talk - June 4, 2008
June 4, 2008 by Tony · Leave a Comment
It has been awhile since I’ve done a batch of WordPress Talk links, so here are a few WordPress links for you to enjoy:
- How to Avoid Duplicate Posts in the WordPress Loop - This post by Weblog Tools Collection explains how to avoid duplicate posts in both a single WordPress loop and a double WordPress loop.
- How to Get Rid of the WordPress Visual Text Editor - I know a lot of people do not like using the visual text editor when writing posts. If that sounds like you, Leland does a great job of providing the steps you need to take to remove yours.
- Get the Image WordPress Plugin - Justin Tadlock has released his newest plugin, which was designed to help people with images that use Magazine WordPress themes.

![Subscribe to [Blog Tutorials]](http://blogtut.com/wp-content/themes/BlogTutorialPro/images/rss.gif)
![[del.icio.us]](http://blogtut.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://blogtut.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://blogtut.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://blogtut.com/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://blogtut.com/wp-content/plugins/bookmarkify/myspace.png)
![[Newsvine]](http://blogtut.com/wp-content/plugins/bookmarkify/newsvine.png)
![[Reddit]](http://blogtut.com/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://blogtut.com/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://blogtut.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://blogtut.com/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://blogtut.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://blogtut.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://blogtut.com/wp-content/plugins/bookmarkify/email.png)





