Random image in NextGEN but without widget ;)
My favorite plugin for images is NextGEN ( I have already written about it). There was only one small item missing – possibility of displaying random images in the sidebar. Actually such option is offered by plugin author but as a widget and I don’t use them. What to do then?
I have had a closer look at both nggwidget.php (to find out how it works) and nggfunctions.php (to check out how functions are created). Hmm… that looked pretty clean and clear so I decided to give it a try.
From nggwidget.php I’ve copied all lines responsible for display and insert of random and recent images (lines 171 to 272) and pasted them to nggfunctions.php file just above // Global function.
Then in the sidebar I’ve put in the chosen place following function
<?php nggDisplayRandomImages(x,y,z);?>
where x is number of images to display, y = width of thumbnail, z = height of thumb. I had to also change a little nggallery.css (part commented as /* –Sidebar widget–*/ ) to have random images the same style as others and… that’s all.
Works like a charm – I have random image in the sidebar without widget
.
UPDATE: Sometimes I do too much ;). Accidently I’ve discovered you can just activate random images widget under plugin tab in your admin panel and then put in the sidebar code I’ve written above…
24th September 2007 4 comments





Do you know if is is possible to show random pictures of a certain gallery in the sidebar. So i could show two different galleries on top of each other.
As far as I know you CAN’T choose which gallery will be displayed randomly. Pictures are taken from all available galleries.
Welll, it’s not necessary to display the gallery randomly. I just want to set each gallery before calling the function to show random pictures. So gallery A on top with its own pictures and gallery B beneath that.
I asked the question on the forum of Alex Rabe. It’s possible but the code isn’t there yet. So i’m looking for a way to do this. Haven’t got an idea yet if I have to wright a new function.
Thanks worked well, how ever when i add media ( image to a post or page 0 it comes up blank and give me a error code on my browser.
gallery inserts work ok, any idea on why this is happening
Here is the error
Line: 12
Char: 3
Error:Object doesn’t support this property or method
Code: 0
URL: http://www.rockinghamgateway.com/wp-admin/post.php?
action=edit&post=147&message=1&_wp_original_http_referer=http%3A%
2F%2Fwww.rockinghamgateway.com%2Fwp-admin%2Fedit.php
karl