Advertisement
alchymyth

2 random ad positions v1

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