Jump to content

php with image slider (WordPress)


nnvi

Recommended Posts

WordPress Options framework, I have 10 available slides for user to upload. for the markup for the slider i have.

1
2
3
4
5
6
7
8
9
10
11
12
13     <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!

 
1
2
3
4
5
6
7
8
9
10
11     
  <?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

 

Link to comment
Share on other sites

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>';
Link to comment
Share on other sites

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.  :happy-04:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.