Title: Insert ads into Infinite Scroll
Last modified: August 21, 2016

---

# Insert ads into Infinite Scroll

 *  Resolved [Steve D](https://wordpress.org/support/users/steadwell/)
 * (@steadwell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/)
 * I’ve been able to insert ads into my posts with Infinite Scroll enabled using
   this
 *     ```
       <?php if ( have_posts() ) : ?>
       <?php $countpost = 0; ?>
       		<?php /* Start the Loop */ ?>
       		<?php while ( have_posts() ) : the_post(); ?>
   
       			<?php
       				/* Include the Post-Format-specific template for the content.
       				 * If you want to overload this in a child theme then include a file
       				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
       				 */
       				get_template_part( 'content', get_post_format() );
       			?>
       <?php// echo $countpost ?>
       <?php if ( ($countpost == 3) ) : ?>
       <?php { wp_template_ad("2"); ?>
       <?php $countpost = 0; } ?>
       <?php
       endif;
       $countpost++;
       ?>
   
       		<?php endwhile; ?>
       ```
   
 * in my “the loop” logic in both index.php and archive.php, the only looping that
   I can find in my theme files.
 * The problem is that it works for the initial page load, but apparently uses some
   other “the loop” to append the additional posts during infinite scrolling. Thus,
   only a couple of ads show up in the posts listed.
 * Can anyone help me out with this?
 * [http://wordpress.org/plugins/jetpack/](http://wordpress.org/plugins/jetpack/)

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

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/#post-4502444)
 * I would recommend that you check [this tutorial](http://ottopress.com/2012/jetpack-and-the-infinite-scroll/)
   to find out how your theme is built and where the loops used by Infinite Scroll
   are located.
 * Let me know if it helps.
 *  Thread Starter [Steve D](https://wordpress.org/support/users/steadwell/)
 * (@steadwell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/#post-4502473)
 * Thanks for the quick response Jeremy!
 * It appears that Jetpack IS processes the additional posts with it’s own queries
   after the standard modules have completed their reads. I’m still looking into
   more approaches either in stead or in addition to what I’ve got in place.
 * The suggested reading is somewhat helpful, though I’d read it previously but 
   there is apparently something I’m missing as to how it relates to my Book Lite
   child theme.
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/#post-4502536)
 * What happens if you use `get_template_part` to add your ad template to `content.
   php`, and check the post count there?
 *  Thread Starter [Steve D](https://wordpress.org/support/users/steadwell/)
 * (@steadwell)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/#post-4502541)
 * I think I’ll just put one ad in a floating div that will be independent of the
   posts list. That would likely be the best approach since I don’t want to inundate
   the viewer with too many ads.
 * Thanks for your help!

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

The topic ‘Insert ads into Infinite Scroll’ is closed to new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

## Tags

 * [ads](https://wordpress.org/support/topic-tag/ads/)

 * 4 replies
 * 2 participants
 * Last reply from: [Steve D](https://wordpress.org/support/users/steadwell/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/insert-ads-into-infinite-scroll/#post-4502541)
 * Status: resolved