function partners($atts ) {
extract(shortcode_atts(array(
'ids' => null,
'extra_options' => 'something' <----------------- in wordpress I can read this value using local $extra_options
), $atts));
global $extra_options; <----------------- trying to change local var to global
function print_partners_scripts() {
global $extra_options; <----------------- reading above variable
echo '<script type="text/javascript">' . "\n";
echo 'jQuery(document).ready( function() {'. "\n";
echo ' $(".partners-slider").bxSlider({
slideWidth: 924,
auto: 0,
autoStart: 0,
moveSlides: 1,
minSlides: 3,
maxSlides: 8,
pager: false,
controls: false,
slideMargin: 5,
' . $extra_options . ' <----------------- var is empty
});' . "\n";
echo '});' . "\n";
echo '</script>' . "\n";
}
add_action( 'wp_footer', 'print_partners_scripts' );
$ids = explode( ',', $ids );
$output = '<div class="ps-wrap"><div class="partners-slider">';
foreach($ids as $id) {
$img_attr = wp_get_attachment_image_src( $id, 'full' );
$output .= '<div class="pslide"><img src="' . $img_attr[0] . '" /></div>';
}
$output .= '</div></div>';
return $output;
}
嗨,我正在尝试读取 print_partners_scripts() 中的 var $extra_options。该变量在 partners() 函数中设置。我试图让它全球化并简单地在某个地方使用它,但我想我做错了什么;)
提前致谢 !