简体   繁体   English

ACF文字上一篇

[英]ACF text previous post

I have a ACF text field. 我有一个ACF文本字段。

I want to use the previous post on these texts, but my code doesn't work... 我想在这些文本上使用上一篇文章,但是我的代码不起作用...

This is this line that doesn't work : 这是行不起作用的:

var r = parseInt('<?php the_field('red', $prev_post->ID); ?

Here's my code : 这是我的代码:

 $(document).ready(function() {

    $(".next_image_cover a").hover(

        function() {

        var r = parseInt('<?php the_field('red', $prev_post->ID); ?>'); 
        var g = parseInt('<?php the_field('green', $prev_post->ID); ?>'); 
        var b = parseInt('<?php the_field('blue', $prev_post->ID); ?>'); 


        $("body").stop().animate({"background-color": "rgb(" + r + "," + g + "," + b + ")"}, "200");
        },
        function() {

        $("body").stop().animate({"background-color": "#e6e6e6"}, "200");

    }); 

您不能在JavaScript中使用php变量-

parseInt('<?php the_field('red'); ?>', **$prev_post->ID**); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM