Top

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.

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

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.

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

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:

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

Bottom