The Personal Blog of
James Little writes about Affiliate Marketing, SEO, PPC, Blogging, Internet Revenue, and other random thoughts

Gallery2 (g2) Widget Support

Uncategorized

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.

One Comment

  1. James says:

    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

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree