anatta Friend
#266230

Thanks for this incredibly useful post. I have modified your function slightly so that I can specify an image if I want, or default to a random set of images. The function uses static paths, so please note that I am using the ja_iolite template and that my static images are in a folder header2 – so please make sure that you adjust the paths to fit your environment.

Also, for those less experienced with PHP, be sure to post this function before the final ‘}’ so that it is included in the JA_Tools class, otherwise you will find that it does not work.

Hope this helps someone ;).

<blockquote>function showHeaderImage () {
$Itemid = JRequest::getInt( ‘Itemid’);

//.. DEFINE YOUR ARRAY OF IMAGES HERE …….
$images_array = array(“70” => “/templates/ja_iolite/images/header2/hd-1.jpg”,
“71” => “/templates/ja_iolite/images/header2/hd-2.jpg”,
“default” => “/templates/ja_iolite/images/header/”.$this->getRandomImage(“templates/ja_iolite/images/header”) # random image function will be called if Itemid not in the list
);
//…………………………………….

//.. Now checking ………………………
$image = “”;
$found = false;
foreach ($images_array as $key => $value) {
if (strval($key) == strval($Itemid)) $found = true;
}

if ($found) {
$image = $images_array[“$Itemid”]; # Return the image if found
} else {
$image = $images_array[“default”]; # else, we return random image
}

return $image;
}
</blockquote>

You will also need to adjust index.php to call this function as explained above.