WordPress and automatically use slimbox for pictures

Playing around with WordPress for another homepage which will have a lot of pictures I discovered the slimbox plugin which I think is really nice.

Only downside is, that you have to add the rel=’ lightbox’ to every picture you use. This isn’t handy. I found a post where this is fixed with some java-script.

I add slimboxjs.diff here, so it’s easier to apply:


--- slimbox.js_ORIG 2007-12-19 06:55:10.000000000 +0100
+++ slimbox.js 2008-01-07 10:59:00.000000000 +0100
@@ -189,4 +189,17 @@
}
};

+function autoLightbox()
+{
+ var anchors = document.getElementsByTagName(“a”);
+ var imgex = /\.(jpg|jpeg|gif|png|bmp)$/;
+ for (var i = 0; i < anchors.length; i++){
+ var anchor = anchors[i];
+ if (anchor.getAttribute(‘href’) && (anchor.getAttribute(‘href’).toLowerCase().search(imgex) >= 0)){
+ anchor.setAttribute(‘rel’, ‘lightbox’);
+ }
+ }
+}
+
+window.addEvent(‘domready’, function(){ autoLightbox();})
window.addEvent(‘domready’, Lightbox.init.bind(Lightbox));


I like this plugin even better:

http://mdkart.fr/blog/plugin-add-lightbox-pour-wordpress/

Leave a Reply

Your email address will not be published. Required fields are marked *