0
votes

I wish to display 1 of 4 random images on the landing page. To make it easy for the customer I have a settings page menu item where they can input the URL for non-coding users. In the Functions-admin.php I have the following code, function settings_page_admin() {

for ($i=1 ; $i<=4 ; $i++) {
    register_setting( 'sah-group', 'home_img_'.$i );
}

I try calling it on the home-header.php,

<script type="text/javascript">
var imageURLs = for ($i=1 ; $i<=4 ; $i++) {
    <?php echo get_feature_img ( 'home_img_'.$i () ); ?>
    };
function getImageTag() {
var img = '<img src=\"';
var randomIndex = Math.floor(Math.random() * imageURLs.length);
img += imageURLs[randomIndex];
img += '\" alt=\"Some alt text\"/>';
return img;
}
</script>
<div id="home_banner" class="home-header" <?php echo get_home_img( 'home_img_'.$i ) ?>>

I'm missing a step (or more) on getting this right, can't see the forest for the trees. Assistance appreciated.

You are not calling settings_page_admin() anywhere. Also notice that you can't easily mix Javascript and PHP, $i is unknown to PHP since it's a JS variablebrombeer