I was working on a website for a nonprofit client, and I wanted a simple banner at the top of the page to rotate between a few different images. Yours fit the bill for simplicity and ease-of use, but flaws in IE prevented me from being able to use it correctly due to the fact that IE improperly rendered whitespace at the bottom of my banner div unless the image was the background image.
I solved the problem by using your code snippet and altering it somewhat so that it could be used in multiple templates with no modification.
Here's what I did:
PHP Code:
<div style="height:180px; width:770px; background: url(<?php echo "templates/$cur_template/images/banners/banner",rand(1,2),".jpg" ?>) no-repeat; ">
So long as you have an
images/banners directory in your template directory, this little snippet will return a valid image in that directory without requiring an explicit pathname. This will allow for easy copying of your template, because the path will be calculated each time.
The height and width of the banner must be explicitly set, of course, but what a payoff.