0

I'm using a background gallery plugin (http://buildinternet.com/project/supersized/) in my project, but when I was attaching it to my wordpress website, I've found a problem that I'm not able to deal with. The gallery calls images by javascript. The function is something like that:

<script type="text/javascript">
    jQuery(function($){
        $.supersized({
            slides  : [
                    {image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/kazvan-1.jpg'},
                    {image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/kazvan-2.jpg'},  
                    {image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/kazvan-3.jpg'}
                ]
        });
    });
</script>

The problem is that the images I need to display are taken from wordpress DataBase. And within a javascript I have no idea of how it works. Is there any way of making a php call? The php foreach request I used without the gallery plugin to call the images is this:

<?php foreach ( $images as $image ) : ?>
    <img src="<?php echo $image->thumbnailURL ?>" />

    <?php if ( $image->hidden ) continue; ?>
    <?php if ( $gallery->columns > 0 && ++$i % $gallery->columns == 0 ) { ?>

    <?php } ?>
<?php endforeach; ?>

Thanks for any help.

akplebani
  • 81
  • 2
  • 13

2 Answers2

1

you can put this php code for echo this javascript

<script type="text/javascript">
  jQuery(function($){
     $.supersized({
        slides  : [

                <?php $out=array();
                    foreach ( $images as $image ){ 
                       if ( $image->hidden ) continue; 
                       $out[]="{image :'".$image->thumbnailURL."'}";

                   } 
                   echo implode(",",$out);?> 
            ]
    });
  });
  </script>

or you can use json for this because of the slides input is json see this page for this How to make a JSON call to a url?

Community
  • 1
  • 1
mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22
1

All that your web page is doing is to prepare a final answer to be sent to the client's browser to read. To prepare this answer you can use both server-side and client-side code, no matter how they are mixed together. If you need database elements in a script definition, you can do it like this:

<script type="text/javascript">
// client-side
<?php
// server-side
?>
// client-side
</script>
Frederik.L
  • 5,522
  • 2
  • 29
  • 41