Gallery2 (g2) Widget Support

After changing my hosting provider a few months back I finally got around to putting my image gallery back online.   I installed F-Spot on Gnome and organised a bunch of my photos (not all of them yet) into Tags.  I then put a fresh install of Gallery2 up and uploaded them all though F-Spot.  Simple enough.

Next however, I wanted to display a random image in the sidebar of this blog which is hosted on the same server but on a different domain.  I picked up the line of php from the Image Block section of gallery and tried to put this in one of the text widgets.

Text Widgets don’t support PHP however.

I looked all over the Web and couldn’t find a solution; I tried a few different widgets but none of which seemed to work.  I even tried a widget which lets you run PHP Execs but it gave a security error generated by Gallery2.

In the end I came up with a solution.

I inserted the PHP External Image Block code generated by Gallery2 and put this line into a .php file (I called it photos.php and located it in the wp-content directory).  Then I created a new text widget and setup an iFrame with the following aspects:

src=”/wp-content/photo.php” FRAMEBORDER=”0″ MARGINWIDTH=”0″ MARGINHEIGHT=”0″

The result is the Random image that you should be able to see to the left.  It’s hardly ideal but seems to work.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

RSS feed | Trackback URI

1 Comment »

Comment by James
2007-02-19 12:44:38

A little update to this one.

You may need to set a width - it was breaking my site in IE6 without one. In which case just add this to the iFrame bits (so width=”150″ is what I have.

Also you will need to get the image to open in a new window. To do this, change the part in photos.php to something like this:

/gallery/main.php?g2_view=imageblock.Exter
nal&g2_blocks=randomImage&g2_linkTarget=_blank

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> in your comment.