• ilushkin

    (@ilushkin)


    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)
  • Maybe use wp_rand()?

    <?php $count = wp_rand(1,9); ?>

    Thread Starter ilushkin

    (@ilushkin)

    Thank you

    Tried that and <?php ($count==wp_rand ( $min = 2, $max = 10 )) : ) ?>

    Blog crashes.

    I’m not surprised. Did you try the simpler code I posted?

    Thread Starter ilushkin

    (@ilushkin)

    tried

    <?php $count = 1; ?>

    post

    <?php $count = wp_rand(1,9); ?>

    ad

    <?php endif; $count++; ?>

    Blog crashes.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    So you have a syntax error? Check your apache error logs if you only see a white screen

    Can you paste the entire loop somewhere like pastebin.com and then post the link here?

    Thread Starter ilushkin

    (@ilushkin)

    original (non random)
    https://pastebin.com/uB9S6cWz

    Modified like this https://pastebin.com/MPYd1F2z Produces white page ….

    The last endif at the end of the file is orphaned since you removed the opening if statement.

    Thread Starter ilushkin

    (@ilushkin)

    Wow. I’m not good in php and programming. Thank you.

    Still, this code https://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.