Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.