Brief Adsense Question

Status
Not open for further replies.

JamesH

New member
Jun 25, 2006
2,514
26
0
Will Google get pissed if I copy and paste my Adsense code into the Wordpress if-else loop? It stops posting the ads after 3 which is cool, I just don't want to piss off the boss. Thanks.
 


I wouldnt beings that setting an ad after any post in the index or Archive is so easy to do. Why take a chance when it would only take you minuets to do it the right way?
 
Well right now Adsense delux is sucking the big one, and won't work. I always have trouble trying to get this baby to work right. Also, what exactly would be the right way to do it? Please note that I have basically no knowledge with PHP.
 
In your Wordpress theme editor locate:

Code:
 <?php if (have_posts()) : ?>
Above that place this:

Code:
 <?php $count = 1; ?>
Next find your <div="entry"> or whatever it is in your templates and below it add:

Code:
 <?php if ($count == 1) : ?> 

Your Adsense Code Here...

<?php endif; $count++; ?>
To change what post you want your adsense ad to show up change the ($count == 1) number to whatever you want. example: ($count == 3) will place the adsense block after the 3rd post.

And since I'm in a generous mood I'll give you a little tip that I use for my sites. I generally have 10 post showing at a time where I have a 468 x 60 just above the first post, 336 x 280 after the fifth post and another 336 x 280 just under the page pagination. I've tested many layouts and this gives me the highest ctr.

If you're using adlogger I found that I got a shit load of ghost clicks with the ad by the pagination so I just added a style to it to distinguish it from the next/previous buttons:

Here is the css:

Code:
 .style {
    background: #ffffff;
    background-position: 15px 50%; /* x-pos y-pos */
    text-align: center;
    padding: 5px 20px 5px 20px;
    border-top: 1px dotted #CCCCCC;
    border-bottom: 1px dotted #CCCCCC;
    margin-top: 25px;
    }
Here is the html:

Code:
<div class="style">

Your adsense code here...

</div>
Use whatever name you want for the divs.
 
Doobus, it doesn't work. It worked for the first post, but when I tried to implement the 5th post one as you described, it placed the ad under the 2nd post, and left out the ad in the first post. :)
 
Code:
<?php get_header(); ?>
        <div class="main-narrow">

<?php $count = 1; ?>

            <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
            <div class="post" id="post-<?php the_ID(); ?>">
                <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <div class="entry">


                    <?php the_content(); ?>

                    <p class="postinfo">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
                    </p>


    <?php if ($count == 5) : ?>

    <div class="alert">Adsense Code Here...</div>

    <?php endif; $count++; ?>

                    <!-- <?php trackback_rdf(); ?> -->

                </div>
            </div>
            <?php endwhile; ?>

            <?php include (TEMPLATEPATH . '/browse.php'); ?>

            <?php else : ?>
            <div class="post">
                <h2><?php _e('404 Error: Not Found'); ?></h2>
            </div>
            <?php endif; ?>

        </div>

<?php get_footer(); ?>
Place that entire thing into your main index template, make sure you put your adsense code in, I set it to be place in the 5th spot, works fine from my end.

also make sure to put this in your css:

Code:
.alert {
    background: #000000;
    text-align: center;
    border-top: 1px dotted #CCCCCC;
    border-bottom: 1px dotted #CCCCCC;
    margin-top: 25px;
    }
Style it to your liking.
 
Thanks man, it all worked. I thought you could use that code to do multiple adsense units in the loop, but I was mistaken. I added in the other adsense codes manually. Everything is working A okay.

However, could you explain why you used the CSS to make the 338x280 stand out so much?
 
Personal preference I guess, I just like to separate it a bit instead of it hugging the post above it.
 
Status
Not open for further replies.