Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with javascript & php please re Slideshow in a theme
#1
I want to improve my Holford theme with an integral slideshow as a header image. I have found what appears to be a suitable script for a php environment here:
http://www.softcomplex.com/products/tigra_fader/
I am keen to use this script because a user can just put any number of any images, pngs, gifs, with any name and any size in the folder in the theme and they will be used in the slideshow, and the settings allow its use as a random image selector as well as a slide fader.

Anyway. This is the sample page provided to show the implementation of the script:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>Tigra Fader Sample #4 - Automatically show all image files in the directory</title>

    <!-- link Tigra Fader script file in the header or anywhere before the first slide show initialization -->
    <script language="JavaScript" src="tFader.js"></script>
</head>
<body>

<!-- at the location where you want slideshow to appear configure and initialize the instance -->
<script language="JavaScript">

    // configuration structure
    var A_TPL = {
        // randomize the array each time page loads
        'random' : false,
        // number of transparency changes during the transition
        //    increase for smoother transition, reduce for less CPU usage
        'steps' : 20,
        // transition duration in seconds
        'transtime': .5,
        // slide time in seconds
        'slidetime': 1,
        // width of the slide (optional)
        'width' : 300,
        // height of the slide (optional)
        'height': 225,
        // alt text for the image (optional)
        'alt' : 'Sample Tigra Fader Slideshow',
        // css class assigned to the slide <img> (optional)
        'css' : ''
    };

    // list of images to display
    var A_ITEMS = [<?php
        $s_path = 'img/';
        $a_types = array ('jpg', 'gif', 'jpeg', 'png');
        $a_images = array ();
        $h_dir = opendir($s_path);
        while ($s_file = readdir($h_dir)) {
            $s_type = strtolower(substr(strrchr($s_file, '.'), 1));
            if (in_array($s_type, $a_types))
                array_push($a_images, "\n\t\t'$s_path$s_file'");
        }
        closedir($h_dir);
        sort($a_images);
        echo join(',', $a_images);
?>

    ];
    // fader initialization    
    var mySlideShow = new tFader (A_ITEMS, A_TPL);

</script>

</body>
</html>
So in the <head> section of my template.php I add the line as above but altered to
Code:
<script language="JavaScript" src="<?php get_theme_url(); ?>/tFader.js"></script>
And I can see I have to do something similar in the script configuration where it is
Code:
// list of images to display
    var A_ITEMS = [<?php
        $s_path = 'img/';  ....
To correct the path to the img folder.

And that's where I have been stuck for hours. I know php nested in php is a no no, and I know the php will need to be in double quotes if it is to be read as a string... but I cannot by thought, struggle or trial and error get the script to find the img folder.

Thanks
Reply


Messages In This Thread
Need some help with javascript & php please re Slideshow in a theme - by Timbow - 2012-11-16, 21:16:35



Users browsing this thread: 1 Guest(s)