I am trying to make a shortcode that will create a dynamic dropdown list of downloadable file links, that once selected, html will show a download link below the dropdown.
Here is the end result of how the shortcode will function: http://jsfiddle.net/KKyE9/
I am struggling with how to turn the shortcode array into a multidimensional array or if that is the right approach.
For example, via the shortcode I am passing attributes that are not defined in the shortcode function but beed to be created inside the function.
[sc total_options="10" option1="module 1" link1="http://cisco.com" label1="Click Here to download Module 2 audio file" option2="module 2" link2="http://wordpress.com" label2="Click Here to download Module 2 audio file" option3="module 3" label3="Click Here to download Module 3 audio file" link3="http://cisco.com" option4="module 4" label4="Click Here to download Module 4 audio file" link4="http://wordpress.com"]
So option1, link1, label1, option2, link2, label2...etc. need to be created when the shortcode attributes are extracted.
I have a working model that creates the dropdown list and displays the html link below but that only works for a single link.
My challenge is passing the keyed attributes (option1, option2from the shortcode into the shortcode function so that I can use them in a loop and dynamically create the dropdown list options.
I am sure the code can be better but I was just trying to get it to work first for a single attribute.
function shortcode_dd_list($atts, $content = null) {
extract(shortcode_atts(array(
"total_options" => '',
"option" => '',
"label" => '',
"link" => ''
), $atts));
$output = '';
$output .= '<select id="wlmm-select-dropdown">';
$output .= '<option value="option0">Please select a module to download</option>';
$i = 1;
while ( $i <= $total_options ) {
$output .= '<option value="'.$option'">'.$option.'</option>';
$i++;
}
$output .= '</select>';
$i = 1;
while ( $i <= $total_options ) {
$output .='<div id="'.$option.'" class="wlmm-select-dropdown-group">'.'<a href="'.$link.'">'.$label.'</a></div>';
$i++;
}
return $output;
}
add_shortcode("sc", "shortcode_dd_list");
Ideally I would rather setup the dropdown like this from the following series of schortcodes, its easier to read but I keep getting 4 dropdown boxes.
[sc total_options="4"]
[sc option1="Module 1" label1="Module 1 download" link1="http://bitBucket.com"]
[sc option2="Module 2" label2="Module 2 download" link="http://lostInSpace"]
[sc option3="Module 3" label3="Module 3 download" link="http://null"]
[sc option4="Module 4" label4="Module 4 download" link="http://error.com"]