Here's a little something I just whipped up. It will look for the images in a single folder (images in this case) whose path can be set. For instance, as currently configured, on March 14 it will look for, in this order:
images/3-14-2012.jpg
images/3-14.jpg
images/3.jpg
images/default.gif
So if you have an image for that date in that year, it will grab it, next it will look for one for that date in any year. Next it will look for one for that month in any year. Finally it will retrieve the default image - the one to show if none of the others are found. It will show one and only one image, the first found that fit the descending criteria I just outlined. The link beneath the image will be to the wiki page for that date.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Daily Image - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<img id="dailyimage" src="images/default.gif" alt="daily image" title=""><br>
<a id="dailylink" href="http://en.wikipedia.org/wiki/January_1" target="_blank">Wiki Dates</a>
<script type="text/javascript">
// Daily Image Script (c)2012 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
;(function(){
var folder = 'images/'; // set image folder
var diag = true; // true or false. true will alert a list of the images the code is looking for.
////////////////////// No Need to Edit Below Here //////////////////////
var d = new Date(), dm = d.getMonth() + 1, dd = d.getDate(), dy = d.getFullYear(),
files = [
[dm, dd, dy].join('-') + '.jpg',
[dm, dd].join('-') + '.jpg',
dm + '.jpg',
'default.gif'
], file, months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
function loadError(i){
var img = new Image();
img.onload = function(){
document.getElementById('dailyimage').src = this.src;
document.getElementById('dailylink').href = 'http://en.wikipedia.org/wiki/' + months[dm - 1] + '_' + dd;
document.getElementById('dailylink').innerHTML = 'Wiki Date: ' + months[dm - 1] + ' ' + dd;
};
img.onerror = function(){
if(++i < files.length){loadError(i);}
}
img.src = folder + files[i];
}
loadError(0);
if(diag){alert(folder + files.join('\n' + folder));}
})();
</script>
</body>
</html>
Edit: I also have a version that can look in subfolders of the folder by month. It would make organizing the images easier. Let me know if you're interested.
Bookmarks