Dr Gonzo’s theme

the php code that makes the random banner work...

A page with all the current banners can be found at http://www.bodmas.org/banners/

My current home-made theme for this page is a very simple table based layout ripped off from Sunir Shah’s home page. As I personally prefer to edit php code in Text Wrangler on the computer rather than a poky textarea box within WordPress, all the php code for the site is in one index.php file. A minimal style sheet specifies preferred fonts and link styles and contains the text headers that the wordPress themes system needs.

If you reload the page, you should see a randomly chosen banner picture – one of 10 choices at present, with more to come later. The code snippet at the top of this post explains how this stunningly unoriginal trick works. I have 10 banner files in the site images file, named banner0.jpg, banner1.jpg and so on up to banner9.jpg. The rand(a, b) function in php returns a random integer between a and b. The sprintf() function in php allows us to build a file name based on the random number using a syntax familiar from C hacking. I guess the same effect could be achieved using client side scripting in Javascript.

I have had the impudence to name this theme (which will be packaged for release soon, with the banners in a folder within the theme folder as they should be) after Dr Gonzo of Fear and Loathing in Los Angeles fame as the theme is not XHTML compliant and does not use CSS for layout. The theme is cheap and cheerful and it got the job done quickly.

We had a good time finding images suitable for cropping for themes. They are all 800 by 200 pixels in size. I have used the old trick of setting the image width to 100% so that the image will always span the available browser window. If you alter the width of the browser window so that the image looks ‘right’, then you will have a browser set to roughly the width that these pages were designed for.

Web design students have to cope with course specifications that are a few years out of date – a Foundation degree Web Authoring module specification demands the use of ‘nested table based layouts’ for full marks! This theme may help a little.

Comments are closed.