Advertisement
alchymyth

ad in random position in loop

Mar 25th, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php $ad_positions = array(1,2,4); // array of preset possible ad positions
  2.  
  3. do { $rnd_ad = $ad_positions[rand(0,count($ad_positions)-1)]; } while ($rnd_ad >= $wp_query->post_count); ?>
  4.  
  5. <?php if(have_posts()) : while(have_posts()) : the_post(); // start of the loop // ?>
  6.  
  7. some possible post output here
  8.  
  9. <?php if( ($wp_query->current_post+1) == $rnd_ad ) : ?>
  10. adsense code here
  11. <?php endif; ?>
  12.  
  13. more possible post output here
  14.  
  15. <?php endwhile; endif; // end of the loop // ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement