Apply banners in pphbb3 using javascript
25Nov2008 Filed under: dev Author: DanHelping out a frequent visited phpbb3 based forum – I’ve been looking for a simple banner system for phpbb3, the search have been dreadfull…
I ended up doing this simple thing in 10 minutes.
Added the following in styles/themename/template/overall_header.html in the theme:
-
<div id="banner">
-
<!– INCLUDE ../../../banners.html –>
-
</div>
Added the file banners.html in the root of the board:
-
<script type="text/javascript">
-
-
function Banner(src, url) {
-
this.url = url;
-
this.src = src;
-
}
-
-
function applyBanners() {
-
if (banners.length == 0) return;
-
with (banners[Math.floor(Math.random() * banners.length)]) {
-
document.write(’<a href="’ + url + ‘"><img src="’ + src + ‘" alt="Banner"/></a>‘);
-
}
-
}
-
-
// Apply banners here
-
var banners = [];
-
banners[banners.length] = new Banner(’http://anotherdan.com/banner1.gif’, ‘http://anotherdan.com’);
-
banners[banners.length] = new Banner(’http://anotherdan.com/banner2.jpg’, ‘http://music.anotherdan.com’);
-
-
// render banners if any…
-
applyBanners();
-
-
</script>
This could be alot cleaner so the guy maintaining only had the array of banners in the file, but this was a proof of concept.
Enjoy…
Holger
January 23rd, 2009 at 1:39 am
Ta daaa!