我有一个函数可以在我的 WordPress 主题中初始化一个图像滑块,但是我无法将 PHP 变量传递给它。这是代码:
function slideshowSettings ($pause_time) {
$code = "<script>
jQuery(function(){
jQuery('#camera_wrap_3').camera({
height: '40%',
thumbnails: true,
time: ".$pause_time.",
fx: '".$transition_effect."',
transPeriod: ".$transition_speed.",
autoAdvance: ".$auto_advance.",
minHeight: '50px',
mobileNavHover: false,
imagePath: '".get_template_directory_uri()."/images/'
});
});
</script>";
echo $code;
}
add_action('wp_head', 'slideshowSettings');
变量分配在函数上方,但我从函数获得的输出如下所示:
<script>
jQuery(function(){
jQuery('#camera_wrap_3').camera({
height: '40%',
thumbnails: true,
time: ,
fx: '',
transPeriod: ,
autoAdvance: ,
minHeight: '50px',
mobileNavHover: false,
imagePath: 'http://www.brainbuzzmedia.com/themes/simplybusiness/wp-content/themes/simplybusiness/images/'
});
});
</script>
我怎样才能传递这些变量?