我正在尝试将元素ID值传递给add_action()
,这又在页脚中设置了Slick Slider的JS。
我得到的结果是:
$("#").slick({...
但是我想要的是:
$("#rtt_grid_carrousel_5bd9bbeabd625").slick({...
到目前为止,这是我的代码:
$uniqid = uniqid('rtt_grid_carrousel_');
js_rtt_grid_carrousel( $uniqid );
function js_rtt_grid_carrousel( $uniqid ) {
add_action('wp_footer', function( $uniqid ) {
?>
<script id="rtt_grid_carrousel" type="text/javascript">
$(document).ready(function () {
$("#<?php echo $uniqid ?>").slick({
dots: false,
arrows: false,
infinite: false,
slidesToShow: 1,
slidesToScroll: 1,
draggable: false,
vertical: false,
centerMode: false,
adaptiveHeight: true,
// fade: true,
// cssEase: "linear",
});
});
</script>
<?php
});
}
-编辑- 沿道路进行编辑。 因此,我们发现php var确实传递给了
js_rtt_grid_carrousel()
但不是
add_action('wp_footer', function(){...}); inside that function
答案 0 :(得分:1)
啊!我找到了! :)你们给了我一些思考的东西。 And searching along I found this here.
$uniqid = uniqid('rtt_grid_carrousel_');
js_rtt_grid_carrousel( $uniqid );
function js_rtt_grid_carrousel( $uniqid ) {
add_action('wp_footer', function() use ( $uniqid ) {
?>
<script id="rtt_grid_carrousel" type="text/javascript">
$(document).ready(function () {
$("#<?php echo $uniqid ?>").slick({
dots: false,
arrows: false,
infinite: false,
slidesToShow: 1,
slidesToScroll: 1,
draggable: false,
vertical: false,
centerMode: false,
adaptiveHeight: true,
// fade: true,
// cssEase: "linear",
});
});
</script>
<?php
});
}
关注以下方面的“使用”:
add_action('wp_footer', function() use ( $uniqid ) {...});
我将不得不更多地研究“使用”,以了解这是什么,但是它有效! :)谢谢大家!