1
我有此drupal的幻灯片,其通过图像标题拉动从文件夹中依次的图像(01_title.jpg,02_title.jpg等。)随机化幻灯片放映图像
我想知道是否有是随机的一种简单的方法图像,所以每次刷新页面时都会以不同的图像开始?
您可以查看这里的幻灯片http://www.rubensteinpr.com/
谢谢!
<div id ="index">
<?php
// Note that !== did not exist until 4.0.0-RC2
$desired_extension = 'jpg'; //extension we're looking for
$banner_imgs_array = array(); // array of banner images
$banner_imgs = ''; // sting of banner images names comma dileneated
if ($handle = opendir(file_directory_path().'/banner_imgs')) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if(($file != ".") and ($file != "..")) {
$fileChunks = explode(".", $file);
if($fileChunks[1] == $desired_extension) //interested in second chunk only
{
$banner_imgs_array[] = $file;
}
}
}
closedir($handle);
$banner_imgs = implode(',', $banner_imgs_array);
}
?>
<div id="banner"><img src="<?php print file_directory_path(); ?>/temp_banner.jpg" width="702" height="310" border="0"></div>
<div id="bannerText">media relations • strategic planning • digital communications • crisis management</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("<?php print file_directory_path(); ?>/banner.swf", "ban", "702", "310", "8", "#ffffff");
so.addParam('menu', 'false');
so.addParam("wmode", "transparent");
so.addParam("base", "<?php print file_directory_path(); ?>");
so.addVariable("banner_imgs", "<?php print $banner_imgs; ?>");
so.write("banner");
// ]]>
</script>
</div>
这段代码现在已经生效,它确实似乎在源代码中对数组进行了混洗,但由于某种原因,即使在清除缓存后,幻灯片仍然按顺序显示图像。也许问题在别处。感谢您的回答! – TheRealBillyT
你确定你把洗牌“前”线?请在“$ banner_imgs = implode(',',$ banner_imgs_array);”之后尝试“echo $ banner_imgs”并看看它是否真的在字符串中洗牌。也许Flash小程序有一个排序功能。尝试重命名图像文件,看看是否改变了顺序。 –