I recently wanted to customize my new Cutline theme to display a random header image with every page load. I noticed that the image was static based on the template. I went into the code and what did I see?
if page == type1
render image 1
if page == type2
render image 2
That’s paraphrased but the gist of it, not great but pretty average PHP in my experience. So I googled to see how to load randomly instead and I found blog postings by people that have created CSS hacks, use a remote call to a random number generator, and other insane ideas. It’s amazing the lengths people go to when they don’t actually understand the capabilities offered by a system. See The Daily WTF for daily examples of such insanity.
Here’s what I came up with:
<img src=”/images/header_<?php echo rand(1, 5); ?>.jpg”/>
Crazy, I know.
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment