Random homepage image generator is being defeated by Drupal's caching.
technicolorenvy - July 27, 2009 - 17:55
In my theme folder, I have created page-front.tpl.php
in the header, i have the following code ...
for background random_img.php is a class that checks a directory. the method randomImgs loads all files of a specified type (jpg), shuffles them, then returns a specified number of results (1). this processing is being defeated by caching
<?php
require("sites/all/themes/theme_name/includes/random_img.php");
$di = new DirectoryItems('sites/all/themes/theme_name/imgs/home_page_headers/');
$filearray = $di->randomImgs("jpg", 1);
foreach($filearray as $key=>$value){
print "<style> #homepage_photo {background: url(/sites/all/themes/theme_name/imgs/home_page_headers/$value.jpg) no-repeat black;} </style>";
}
?>the above code works fine when caching is turned off. I realize i could probably do this via a block, but I would rather have the image be the background of a div AND I figure this would be a good learning opportunity for me to gain insight from those who are more savvy then myself.
I attempted putting this code in my phptemplate_preprocess() function in the theme.php file with the same results... works when i'm not caching, but once i log out or turn caching on, it sticks to one result. I am new to working with preprocess functions so i'm guessing this method may have been way off.
I appreciate and thank you for any input!

Random IMG Options
You could try JQuery (javascript) or
stop the home page being cached with the CachExclude module
http://drupal.org/project/cacheexclude
In business! cacheexclude
In business!
cacheexclude did the trick!
Thanks for the heads up!