I have here a shortcode which generate a slider. Everything works just fine until i try to add another "partners" slider with different options. I can't specific settings for each slider because the print_partners_scripts() function is generated only once. I need to initialize print_partners_scripts() function for every slider with specified in shortcode options. I hope you understand what i mean ;)
function print_partners_scripts() {
global $extra_options, $pslider;
echo '<script type="text/javascript">' . "\n";
echo 'jQuery(document).ready( function() {'. "\n";
echo ' $(".'.$pslider.'").bxSlider({
slideWidth: 924,
auto: 1,
autoStart: 1,
moveSlides: 1,
minSlides: 7,
maxSlides: 8,
pager: false,
controls: false,
slideMargin: 5,
autoHover: true
' . $extra_options . '
});' . "\n";
echo '});' . "\n";
echo '</script>' . "\n";
}
function partners($atts ) {
global $extra_options, $pslider;
extract(shortcode_atts(array(
'ids' => null,
'extra_options' => null
), $atts));
add_action( 'wp_footer', 'print_partners_scripts' );
$pslider = 'partners-slider'.rand(100,999);
$ids = explode( ',', $ids );
$output = '<div class="section row-one"><div class="col ps-gradient"><div class="ps-wrap"><div class="'.$pslider.'">';
foreach($ids as $id) {
$img_attr = wp_get_attachment_image_src( $id, 'full' );
$alt_text = get_post_meta( $id, '_wp_attachment_image_alt', true);
$output .= '<div class="pslide"><a href="' . $alt_text . '"><img src="' . $img_attr[0] . '" /></a></div>';
}
$output .= '</div></div></div></div>';
return $output;
}
add_shortcode('partners', 'partners');
".partners-slider"
. give each of your sliders a unique ID and target that instead.