0

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:

<?php

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:

<?php 

    $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?

1 Answer 1

0

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" ]; 
1
  • 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! Commented Jul 11, 2012 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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