0

If got this full screen background slider (Vegas) on a site thats using Wordpress. Now the slider is called using this script:

<script>
        $("body").vegas({
            delay: 7000,
            timer: false,
            shuffle: true,
            transition: 'fade',
            transitionDuration: 2000,
            slides: [
                { src: "photo01.jpg" },
                { src: "photo02.jpg" },
                { src: "photo03.jpg" },
                { src: "photo04.jpg" }
            ],

            overlay: '01.png'
        });
        </script>

Within Wordpress it is possible to make a loop which "loops" the content that is in that file. What I would like to do is something like this:

....   
    slides: [
                    <?php get_template_part('loop-backgrounds'); ?>
                    { src: "some-file-to-stop-the-backgrounds.jpg" }
                ],
....

The loop-backgrounds would look something like this:

    <?php $loop = new WP_Query( array( 'post_type' => 'backgrounds', 'posts_per_page' => -1, 'orderby'=>'id', 'order' => 'ASC') );
        while ( $loop->have_posts() ) : $loop->the_post(); ?>

        { src: <?php if ( has_post_thumbnail() ) {
                the_post_thumbnail();
            } ;?> },

<?php endwhile; wp_reset_query(); ?>

This some-file-to-stop-the-backgrounds.jpg doesn't have a , at the end so it wouldn't break the code (i think). Is this at all possible?

2
  • Why do think something is not possible? Where did you face problems implementing this? Can you please elaborate, what the question is? (Besides “Is this at all possible?”; Answer: everything is possible) Commented Jun 29, 2016 at 8:44
  • Well... I read somewhere you cant put php inside javascript. And the question is what would be the right way to get this done? Could somebody point me in the right direction? Commented Jun 29, 2016 at 10:55

1 Answer 1

1

Since you're using WordPress i'd just find a full width background slider plugin that does what you need out of the box. I use this full width background slider on a few of my websites and it works great and loads fast.

Give it a shot, hope this helps.

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

1 Comment

Thanks for your awnser but i got it working. Just added some php and it worked. I thought it wasn't possible but it worked.

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.