jQuery脚本在Wordpress循环

jQuery script in Wordpress loop

本文关键字:循环 Wordpress 脚本 jQuery      更新时间:2023-09-26

我试图循环一个jquery脚本,使它影响所有的post加载。脚本中有一个php变量,所以把它放在循环中,并认为这已经足够了,但实际上它只适用于第一篇文章。这是我的php脚本

<?php $valutazione0 = simple_fields_get_post_value(get_the_id(), array(3, 1), true);?>
<div class="postbackrotator" id="rotator-<?php the_ID(); ?>" style="height:43px;width:43px"><canvas height="43" width="43" id="my-canvas"></canvas></div>

这里我从简单字段中获得一个值,它在single.php中工作得很好。下面是变量

的脚本
<script type="text/javascript">
    jQuery(document).ready(function(){
     $('#rotator-<?php the_ID(); ?>').rotator({
        starting: 0,
        ending: <?php echo($valutazione0)?>,
        lineWidth: 1.5,
        fontSize: '13px',
        radius: 21
     });
    });
</script>

加载帖子的所有内容都在循环中,但它不起作用。我哪里做错了?

在循环中应用脚本的所有帖子的正确方法是什么?

<script type="text/javascript">
        jQuery(document).ready(function(){
 $('#rotator').rotator({
    starting: 0,
    ending: <?php echo $valutazione0?>,
    lineWidth: 1.5,
    fontSize: '13px',
    radius: 21
})
})
    </script>

Try this