Title: Ad Boxes Between Posts
Last modified: August 19, 2016

---

# Ad Boxes Between Posts

 *  Resolved [mrtumnas](https://wordpress.org/support/users/mrtumnas/)
 * (@mrtumnas)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/)
 * My site- [http://www.growinggroceries.com](http://www.growinggroceries.com) currently
   has only one sidebar ad. I’d like to put image ads in between the posts like 
   they do on [http://www.venturebeat.com](http://www.venturebeat.com) , for instance.
   The only way I could figure to do this was to put the code from Google after 
   the
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> section 
   of the Main Index Template. It worked, but it put an ad after every post, and
   since that exceeded my ad limit, it wouldn’t show the sidebar ads.
 *  How can I put ads inbetween only the first one or two posts?
 * Thanks- james

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-991890)
 * One way to do it would be to put a counter in the loop
 *     ```
       <?php
        $i = 0;
       if (have_posts()) : while (have_posts()) : the_post();
       $i++;
   
       [ ... post code here ... ]
   
       if ($i <= 2) {
          [  Google ad code here ]
       } ?>
       ```
   
 * That will only print the ad code for the 1st and 2nd post.
 * You will probably need to add some additional PHP opening and closing tags once
   you have inserted the post and Google code
 *  Thread Starter [mrtumnas](https://wordpress.org/support/users/mrtumnas/)
 * (@mrtumnas)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-991952)
 * Cool, I give that a try tonight and let you know how it works!
 *  Thread Starter [mrtumnas](https://wordpress.org/support/users/mrtumnas/)
 * (@mrtumnas)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992014)
 * Okay, using that code made my page not load.
 * Do I put the same Google code in both spaces where you say to insert code? I’m
   pretty new to this whole messing around with code thing. Where exactly do I put
   the code you gave me?
 *  Thanks so much!
 *  Thread Starter [mrtumnas](https://wordpress.org/support/users/mrtumnas/)
 * (@mrtumnas)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992034)
 * *bump*
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992035)
 *     ```
       <?php $i = 0;
       if (have_posts()) : while (have_posts()) : the_post();
       $i++; ?>
        POST CODE GOES HERE
       <?php if ($i <= 2) { ?>
        AD CODE HERE
       <?php } ?>
       ```
   
 * You just need to open and close the PHP in a few places, as stvwlf said…
 *  Thread Starter [mrtumnas](https://wordpress.org/support/users/mrtumnas/)
 * (@mrtumnas)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992038)
 * Thanks, that fixed it, guys. You rock
 *  [ollerwe](https://wordpress.org/support/users/ollerwe/)
 * (@ollerwe)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992119)
 * mrtummas,
    could you provide a link to your site? I would like to see how you
   solved the matter, since I have been wondering about the same myself. Best regards
   Erico

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Ad Boxes Between Posts’ is closed to new replies.

 * 7 replies
 * 4 participants
 * Last reply from: [ollerwe](https://wordpress.org/support/users/ollerwe/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/ad-boxes-between-posts/#post-992119)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
