nnvi Posted February 6, 2014 Share Posted February 6, 2014 WordPress Options framework, I have 10 available slides for user to upload. for the markup for the slider i have.12345678910111213 <ul class="slides"> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage'); ?>" /> </li> <li><img src="<?php echo of_get_option('lfam_uploader_cimage2'); ?>" /></li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage3'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage4'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage5'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage6'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage7'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage8'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage9'); ?>" /> </li> <li> <img src="<?php echo of_get_option('lfam_uploader_cimage10'); ?>" /> </li> </ul> but if the user only uploads 3 images, the rest of the lists will show blank...so i've been trying to use php to sort this out. can someone help me with this! 1234567891011 <?php $simg = of_get_option('lfam_uploader_cimage'); if ( $simg ) { if ( $simg['image'] ) { echo '<li><img src=" '.$simg['image'].' " /></li>'; } else { echo "no entry"; }; ?> I need to try and do this for all 10 images...please help Quote Link to comment https://forums.phpfreaks.com/topic/285980-php-with-image-slider-wordpress/ Share on other sites More sharing options...
cyberRobot Posted February 6, 2014 Share Posted February 6, 2014 I'm not sure if this is the issue, but there shouldn't be a semicolon after the last curly bracket. Also note that the code is missing a closing curly bracket for the first if. Try something like the following: <?php $simg = of_get_option('lfam_uploader_cimage'); if ( $simg ) { if ( $simg['image'] ) { echo '<li><img src=" '.$simg['image'].' " /></li>'; } else { echo "no entry"; } } ?> If that doesn't fix the issue, please let us know what errors you see. You could also try displaying the $simg variable to see if it contains what you expect. For example, you could add the following after the variable is set: $simg = of_get_option('lfam_uploader_cimage'); print '<pre>' . print_r($simg, true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/285980-php-with-image-slider-wordpress/#findComment-1467933 Share on other sites More sharing options...
cyberRobot Posted February 6, 2014 Share Posted February 6, 2014 I need to try and do this for all 10 images... Ah, I just noticed that last part. You can use a loop to display all 10 images. You could try something like the following: <?php for($i=1; $i<=10; $i++) { if($i == 1) { $simg = of_get_option('lfam_uploader_cimage'); } else { $simg = of_get_option('lfam_uploader_cimage' . $i); } if($simg && $simg['image']) { echo '<li><img src=" '.$simg['image'].' " /></li>'; } else { echo "no entry"; } } ?> Note that the code is untested...and I'm sure it could be cleaned up a bit. Quote Link to comment https://forums.phpfreaks.com/topic/285980-php-with-image-slider-wordpress/#findComment-1467934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.