I've recently started using the BrightSide theme which was converted to BlogEngine.Net by Henrik Stenbæk (link below)
I really like the header photo on the homepage but though it was a shame that its always the same image. It would be great to show one at random, from a selection of appropriate images.
This got me thinking a little. Maybe I could put together a simple control which would enable the user to specify a directory of appropriate images and then write out the appropriate html to show a random image from that directory.
Well thats exactly what I did, and here it is to download.
RandomImage1.0.zip (1.35 kb)
To install, simply drop into the app_code/controls directory.
Here is an example of how I'm using it with the BrightSide theme. Click on the home page and refresh a few times to see the result.
First of all, you need to edit the css file to remove the background-image reference in #headerphoto. This is because we will be using our own random image, leave the height, width and border settings as they are.
Next, you need to edit site.master. Look for a div with the ID="headerphoto" and replace with this:
<blog:RandomImage ID="headerphoto" ImageUrl="/blog/themes/BrightSide/headerphoto/" runat="server" />
The css for the height, width and border will be picked up from the css file. When the control renders, it will render as in image tag with the ID of the server control, and the src as a random image from that directory.
You can optionally pass in CssClsas="CssClassName" if you would rather define your Css that way.
I've slightly enlarged the header image in the theme so I can get more on, but the concept is still the same. Obviously all of the images need to be the correct size for this to work in this context.
I originally wrote this as a User Control which would have given flexibility to include this in a post or page, but it felt like this was more of a template (site.master) control rather than something to embed in a post/page.
You could use this for example, to do a random image on your sidebar.
Hope someone finds this useful, I'd love to hear any feedback.
Download the Theme: http://www.onesoft.dk/post/2008/01/New-BlogEngine-Theme---Bright-Side-of-Life.aspx