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="https://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( __( '← Older posts', 'ari' ) ); ?></p> <p class="next"><?php previous_posts_link( __( 'Newer posts →', 'ari' ) ); ?></p> <?php endif; ?>
Thank you so much!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Place Ads Between Posts’ is closed to new replies.