WP: Adsense Ad in place of 3rd post.

by lovboa Banned
3 replies
Hello,

I'm trying to do something within my loop.

I have a grid based layout for my blog posts. I would like to have an adsense ad in place of my third blog post.

I have searched Google for some answers, and tried them all. None of them are working.

Here is my loop code in my index.php

Code:
<div id="index-wrap" class="grid-1">
	<div class="<?php echo of_get_option('entry_grid','grid-4'); ?>-wrap clearfix">
	<?php
        if ( have_posts( )) :
            while ( have_posts() ) : the_post();
                    get_template_part( 'content', get_post_format() );  
            endwhile;	
        endif;	

        echo '<div class="clear"></div>';
        att_pagination(); ?>
    </div><!-- .grid-*-wrap -->
</div><!-- #index-wrap .grid-1 -->
From what I've seen, it has something to do with
$postnum == 3 or $count == 3

But I don't know.
If anyone could help me out, I would really appreciate it.

Thanks.
#3rd #adsense #place #post
  • Profile picture of the author GaryCarlyle
    This is only a bad guess as I am not in a position to test the code right now but I think you will need something like this. I hope it helps a bit in lieu of the warrior cavalry arriving to help ya.

    Code:
    <div id="index-wrap" class="grid-1">
        <div class="<?php echo of_get_option('entry_grid','grid-4'); ?>-wrap clearfix">
        <?php
            if ( have_posts( )) :
                while ( have_posts() ) : the_post();
                
    //Ads +1 to post count on each loop.
    ++;
    
    //Determines if 3rd post. Ie, 3rd loop.
    if ( == 3)
    {
    //If 3rd post display Adsense code or whatever.
    
    }
    
    //Else an original WP post
    else
    {
    get_template_part( 'content', get_post_format() );  
    }
            
                     
                endwhile;    
            endif;    
    
            echo '<div class="clear"></div>';
            att_pagination(); ?>
        </div><!-- .grid-*-wrap -->
    </div><!-- #index-wrap .grid-1 -->
    ** Sorry Warrior Forum is not printing my variables anyway for some reason. Not sure how to do that on this forum. Its prob to protect them understandably.
    Signature

    UK TV abroad for free: http://WatchBritishTV.com

    {{ DiscussionBoard.errors[8132532].message }}
  • Profile picture of the author lovboa
    Banned
    Hey Gary,

    Thanks for taking the time to help

    I managed to get it to work last night, but the code I used is pretty messy.

    I'll give yours a try.
    {{ DiscussionBoard.errors[8133535].message }}

Trending Topics