[resolved] Alternate code in my index.php (3 posts)

  1. nick74
    Posted 6 years ago #

    I'm looking to alternate or swap a line of code in my index.php file everytime the page gets re-loaded. I'm new to wordpress and php coding so please go gentle.

    Here is a small chunk of code from my index.php:

    <div id="content" class="narrowcolumn">

    <div style="height:85px"><?php flshow(63); ?></div>

    <?php if (have_posts()) : ?>

    This code shows a flash carousel on my site that has around 7 images in it:
    <div style="height:85px"><?php flshow(63); ?></div>

    I also have around 7 more of these flash carousels. The code for each one goes like this:

    <div style="height:85px"><?php flshow(64); ?></div>
    <div style="height:85px"><?php flshow(65); ?></div>
    <div style="height:85px"><?php flshow(66); ?></div>
    <div style="height:85px"><?php flshow(67); ?></div>


    I was wondering if there is a way to have wordpress show a random flash carousel each time someone visits my site.

    For example it would show this carousel:
    <div style="height:85px"><?php flshow(63); ?></div>
    and then when the page gets reloaded it would show this carousel: <div style="height:85px"><?php flshow(64); ?></div>

    Thanks for any help.

  2. jceresini
    Posted 6 years ago #

    You can use the php rand function. It takes 2 arguments, the minimum and the maximum integers you want it to return:

    <?php flshow(rand($min,$max); ?>

    So, if you wanted it to be between 63 and 67 inclusively, youd use:

    <?php flshow(rand(63,67); ?>

    Theres more info about the function here: http://www.php.net/manual/en/function.rand.php

    [signature moderated Please read the Forum Rules]

  3. nick74
    Posted 6 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.