Why isnt this working?
-
Hey guys
Im trying to add a div that runs a script to display a ad every 8 posts in my loop. Its currently displaying an ad after the 8th post as intended but after that nothing.
Here is my loop
<div class="content-container"> <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'post_type' => array( 'post', 'review'), 'posts_per_page' => 8, 'paged' => $paged ); $the_query = new WP_Query( $args ); ?> <?php $post_counter=0; ?> <?php if ( $the_query->have_posts('paged') ) : ?> <?php while ( $the_query->have_posts('paged') ) : $the_query->the_post('paged'); ?> <?php get_template_part( 'content' ); ?> <?php comments_template( '', true ); ?> <?php $post_counter++; if ($post_counter == 8 || $post_counter == 10) { ?> <div class="ad-box-300x250"> <SCRIPT language="Javascript"> var cpmstar_rnd=Math.round(Math.random()*999999); var cpmstar_pid=57604; document.writeln("<SCR"+"IPT language='Javascript' src='//server.cpmstar.com/view.aspx?poolid="+cpmstar_pid+"&script=1&rnd="+cpmstar_rnd+"'></SCR"+"IPT>"); </SCRIPT> </div> <?php } ?> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> </div> <!-- content-container --> <?php load_more_button(); ?>
Do i have the counter set up incorrectly? I have a load more button that loads the next page of posts underneath could that be whats not working?
Heres my website http://www.gamersgreed.com
- The topic ‘Why isnt this working?’ is closed to new replies.