Title: Random ads
Last modified: August 21, 2016

---

# Random ads

 *  [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * (@ilushkin)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/)
 * Hello,
 * I’m currently running ads after a certain post number.
    I have code like that:
 * <?php $count = 1; ?>
    <?phpif( have_posts( ) ) <?php if ($count==2) : ?>
 * So basically I have an ad running after the second post. I can change that to
   3rd, 4th or etc. But how do I change that to a random number 1 to 10?
    <?php 
   if ($count==2) : ?> need to be changed to random number but less than 10….
 * Thank you.

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

 *  [Dave Naylor](https://wordpress.org/support/users/wpranger/)
 * (@wpranger)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707266)
 * Maybe use wp_rand()?
 * `<?php $count = wp_rand(1,9); ?>`
 *  Thread Starter [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * (@ilushkin)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707273)
 * Thank you
 * Tried that and <?php ($count==wp_rand ( $min = 2, $max = 10 )) : ) ?>
 * Blog crashes.
 *  [Dave Naylor](https://wordpress.org/support/users/wpranger/)
 * (@wpranger)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707285)
 * I’m not surprised. Did you try the simpler code I posted?
 *  Thread Starter [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * (@ilushkin)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707292)
 * tried
 * <?php $count = 1; ?>
 * post
 * <?php $count = wp_rand(1,9); ?>
 * ad
 * <?php endif; $count++; ?>
 * Blog crashes.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707294)
 * So you have a syntax error? Check your apache error logs if you only see a white
   screen
 *  [Dave Naylor](https://wordpress.org/support/users/wpranger/)
 * (@wpranger)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707296)
 * Can you paste the entire loop somewhere like pastebin.com and then post the link
   here?
 *  Thread Starter [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * (@ilushkin)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707299)
 * original (non random)
    [http://pastebin.com/uB9S6cWz](http://pastebin.com/uB9S6cWz)
 * Modified like this [http://pastebin.com/MPYd1F2z](http://pastebin.com/MPYd1F2z)
   Produces white page ….
 *  [Dave Naylor](https://wordpress.org/support/users/wpranger/)
 * (@wpranger)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707335)
 * The last _endif_ at the end of the file is orphaned since you removed the opening
   _if_ statement.
 *  Thread Starter [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * (@ilushkin)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707341)
 * Wow. I’m not good in php and programming. Thank you.
 * Still, this code [http://pastebin.com/w7WgfG59](http://pastebin.com/w7WgfG59)
   puts ads after each post…
 * Very difficult to accomplish I guess I would have to change the position of the
   banner manually from time to time… 🙁 Unless, someone can point me to the right
   direction 🙂

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

The topic ‘Random ads’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [ilushkin](https://wordpress.org/support/users/ilushkin/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/random-ads-1/#post-4707341)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
