我创建了一个Wordpress函数来在任何页面中显示幻灯片.该功能运行良好,我可以添加一个函数调用到我的任何模板页面来显示幻灯片.
样本函数调用: add_slideshow($slideshow_id, $gallery_id, $show_navigation_handles);
我在页脚中硬编了jquery.但是,我想add_action('wp_footer','')在我的main函数中使用jquery添加到页脚,因为每个幻灯片可能有不同的设置(不同的slideshow_id,gallery_id等).
这是我的功能:
function add_slideshow($slider_id, $gal_id, $show_controls){
//get the slideshow images from database and return HTML - A Bit Long to show here but it WORKS!
//add the required script to footer - JavaScript is added to footer but not $slider_id
add_action('wp_footer', function() {
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#" . $slider_id . "').flexslider();
});
</script>";
});
Run Code Online (Sandbox Code Playgroud)
但是PHP变量$slider_id没有传递给发出的javascript,因此我的页脚输出是:
<script type='text/javascript'>
$(document).ready(function(){
$('#').flexslider();
});
</script>
Run Code Online (Sandbox Code Playgroud)
什么时候应该是这样的:
<script type='text/javascript'>
$(document).ready(function(){
$('#some_id_here').flexslider();
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果我使用正确的ID(#actual_slideshow_id)手动将其添加到我的页脚,幻灯片播放就可以了.
我在最后一小时搜索了这个网站,试图找到一个解决方案,但我找不到任何可以适应我的具体问题的网站. …