I’ve created my own admin page for my wordpress theme, I am attempting to upload multiple images to a slideshow, but should the first image be deleted, the second image will take it’s place i.e. if you delete image 1, image 2 will become image 1, if you delete image 3, image 4 will be come image 3.
This works by counting the array and then deleting it by 4
So this works ok, but I would now like to add another slideshow but deleting it by 4 now longer works, for instance when I add another form and add an image, there becomes another array.
Instead of taking away, i some how need to add but I can’t get my head round it, anyone know how i can figure this out?
Here’s the code
function d_hero_image_option_callback() {
$hero_options = get_option( 'hero_options' );
$count=count($hero_options);
$totalimg=$count-4;
$html = '<div id="upload_d_sets">';
for($i=1;$i<=$totalimg;$i++){
if( isset( $hero_options['upload_d_link_1'] ) && $hero_options[ 'upload_d_link_1' ] ) {
$html .= '<div id="dclonedInput'.$i.'" class="dclonedInput">';
$html .= '<input id="cs_product_menu_d_src_'.$i.'" type="text" size="36" name="hero_options[upload_d_link_'.$i.']" value="' . $hero_options['upload_d_link_'.$i.''] . '" /> <input id="cs_product_menu_d_src_'.$i.'_button" type="button" value="Add / Change" class="button-secondary d-upload-button" /> <div class="button dremove">-</div>';
$html .= '</div>';
}
}
$html .= '</div>';
echo $html;
?> <div class="button dclone">Add an Image</div> <?php
}
Basically what this is doing is counting the array
$count=count($hero_options);
Every time I add a new image it will add another to the array, it then counts the array and delete it by 4
$totalimg=$count-4;
Read more here: Multiple media uploads in a wordpress admin page