0

I am using background slideshow in my next wordpress project.

I am using redux framework for options panel.

I want to use JQuery UI Spinner Example 1 for controlling the speed of the slider.

How can I insert php variable into the js file of the slider?

Here is the code:

var cbpBGSlideshow = (function() {

    var $slideshow = $( '#cbp-bislideshow' ),
        $items = $slideshow.children( 'li' ),
        itemsCount = $items.length,
        $controls = $( '#cbp-bicontrols' ),
        navigation = {
            $navPrev : $controls.find( 'span.cbp-biprev' ),
            $navNext : $controls.find( 'span.cbp-binext' ),
            $navPlayPause : $controls.find( 'span.cbp-bipause' )
        },
        // current item´s index
        current = 0,
        // timeout
        slideshowtime,
        // true if the slideshow is active
        isSlideshowActive = true,
        // it takes 3.5 seconds to change the background image
        interval = 3500;
}

I want to do something like this

interval= redux variable name

Thanks

2 Answers 2

1

You can't set a PHP variable inside a .js file unless your server parses .js files as PHP (which it shouldn't because it's a really bad idea in 99% of cases).

One of the options is to define a JS variable in a script block in your PHP file, before you load your JS script (but inside the head or body tags) and then just use that variable in your script. It's as simple as:

var myJSInterval = <?php echo $myPHPInterval; ?>;

And then in the script:

interval = myJSInterval;

Note that if you do this with strings, you need to put quotes around it. And if you want something more complex, you probably want to use JSON.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this syntax:

 <script>
    var interval = <?php echo $php_Variable;?>;
 </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.