Title: Place Ads Between Posts
Last modified: August 20, 2016

---

# Place Ads Between Posts

 *  Resolved [IlanK](https://wordpress.org/support/users/ilank/)
 * (@ilank)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/)
 * Hi, I’d like to place ad units between posts on the front page.
    I know I have
   to put the code in the loop.php. I would like the ads to appear between the three
   posts that I have on the front page (so two ads). I have only been able to get
   it so that three ads appear, between posts and also one at the end. How do I 
   make it so that no ads appear at the end, but just in between posts?
 * Here is my loop.php code:
 *     ```
       <?php /* If there are no posts to display, such as an empty archive page */ ?>
       <?php if ( ! have_posts() ) : ?>
       		<h1><?php _e( 'Not Found', 'ari' ); ?></h1>
       		<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 
   
       'ari' ); ?></p>
   
       <?php endif; ?>
   
       <?php /* Start the Loop. */ ?>
       <?php while ( have_posts() ) : the_post(); ?>
   
       <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
   
       	<?php if (is_sticky()) echo __( '<h3 class="sticky-label">Featured</h3>', 'ari' ); ?>
   
       <?php the_time('l, F d, Y') ?>
       		<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'ari' ), the_title_attribute( 'echo=0' ) ); 
   
       ?>" rel="bookmark"><h2><?php the_title(); ?></h2></a>
       <?php _e( 'Written by', 'ari' ); ?> <?php the_author() ?> // <?php comments_popup_link( __( 'Leave a comment', 'ari' ), __( 'One comment', 'ari' ), 
   
       __( '% comments', 'ari' ) ); ?>
       <br>
       <br>
       	<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
       			<?php the_excerpt(); ?>
       			<p class="meta"><span><a href="<?php the_permalink(); ?>">
       	<?php else : ?>
       			<?php the_content( __('Read more >>', 'ari' ) ); ?>
       			<div class="clear"></div>
   
       			<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'ari' ), 'after' => '</div>' ) ); ?>
   
       	<?php endif; ?>
       <?php if ( count( get_the_category() ) ) : ?>
       				<?php endif; ?>
       	</div>
       	<!--end Post-->
       <div class="ad">
       <script type="text/javascript"><!--
       google_ad_client = "ca-pub-2637633606355131";
       /* left ad square */
       google_ad_slot = "1791464294";
       google_ad_width = 250;
       google_ad_height = 250;
       //-->
       </script>
       <script type="text/javascript"
       src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
       </script>
       </div>
   
       		<?php comments_template( '', true ); ?>
   
       <?php endwhile; // End the loop. ?>
   
       <?php /* Display navigation to next/previous pages when applicable */ ?>
       <?php if (  $wp_query->max_num_pages > 1 ) : ?>
       				<p class="previous"><?php next_posts_link( __( '&larr; Older posts', 'ari' ) ); ?></p>
       				<p class="next"><?php previous_posts_link( __( 'Newer posts &rarr;', 'ari' ) ); ?></p>
       <?php endif; ?>
       ```
   
 * Thank you so much!

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/#post-2968166)
 * you can use the variable `$wp_query->current_post` (starts with 0 zero, and indicates
   the position of the post in the loop) in a conditional statement;
 * example:
 *     ```
       <!--end Post-->
       <?php if( $wp_query->current_post < 2 ) : ?>
       <div class="ad">
       <script type="text/javascript"><!--
       google_ad_client = "ca-pub-2637633606355131";
       /* left ad square */
       google_ad_slot = "1791464294";
       google_ad_width = 250;
       google_ad_height = 250;
       //-->
       </script>
       <script type="text/javascript"
       src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
       </script>
       </div>
       <?php endif; ?>
       ```
   
 *  Thread Starter [IlanK](https://wordpress.org/support/users/ilank/)
 * (@ilank)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/#post-2968167)
 * Thanks, that works great!
 *  [sid5491](https://wordpress.org/support/users/sid5491/)
 * (@sid5491)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/#post-2968710)
 * i am still finding problems with inserting these ads . help me
    here [http://www.exchangemystuff.in/](http://www.exchangemystuff.in/)
 *  [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * (@wpyogi)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/#post-2968711)
 * **[@sid5491](https://wordpress.org/support/users/sid5491/)** – looks like you
   are using a commercial theme (those are not supported on these forums), so you’ll
   need to ask the developer of your theme for help –
 * [http://themeforest.net/item/bazar-shop-multipurpose-ecommerce-theme/3895788](http://themeforest.net/item/bazar-shop-multipurpose-ecommerce-theme/3895788)

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

The topic ‘Place Ads Between Posts’ is closed to new replies.

## Tags

 * [between](https://wordpress.org/support/topic-tag/between/)
 * [footer](https://wordpress.org/support/topic-tag/footer/)
 * [index](https://wordpress.org/support/topic-tag/index/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [thing](https://wordpress.org/support/topic-tag/thing/)

 * 4 replies
 * 4 participants
 * Last reply from: [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/place-ads-between-posts/#post-2968711)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
