WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Wordpress function that loops thru 10 input fields & saves the data from those input fields. The data entered is either an absolute or relative link to an image. The loop looks like this.

<?php for ($i = 1; $i < 11; $i++) { ?>

    <input type="text" name="<?php echo 'fresh_banner'.$i ?>" value="<?php echo $settings['fresh_banner'.$i]; ?>" />

<?php } ?>

The saving looks like this:


function freshSaveThemeSettings() {

    $settings = get_option( "freshThemeSettings" );

        for ($i = 1; $i < 11; $i++) {

            $settings['fresh_banner'.$i] = $_POST['fresh_banner'.$i];


    $updated = update_option( "freshThemeSettings", $settings );



To output one of the images, it goes something like this:


    $settings = get_option( "freshThemeSettings" ); 

    echo $settings['fresh_banner1']; 


What I'm trying to do is randomly display one of the images at a time. Each time the page is refreshed, a new image would be displayed. What is the best way to go about this?

share|improve this question
up vote 0 down vote accepted

This is more a basic PHP question than a WordPress one!

$settings = get_option( "freshThemeSettings" ); 
$random = rand( 1, 11 );

if ( isset( $settings[ "fresh_banner$random" ] ) )
    echo $settings[ "fresh_banner$random" ]; 
share|improve this answer
Yeah I feel ya. But any mention of Wordpress over at Stackoverflow is just askin for it. Thanks a ton for the help, this should work just fine! – onestepcreative Jul 11 '12 at 10:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.