我这里有一个生成滑块的短代码。在我尝试添加另一个具有不同选项的“partners”滑块之前,一切都正常。我无法为每个滑块指定设置,因为print\\u partners\\u scripts()函数只生成一次。我需要为每个在短代码选项中指定的滑块初始化print\\u partners\\u scripts()函数。我希望你明白我的意思;)
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\');