Is Gallery2 Breaking Your Layout?

Thanks to the team at WPG2 (Wordpress Gallery2), it is now relatively easy for us to fully integrate Gallery2 into WordPress. I like to use the default Matrix theme (and this tutorial is designed for it), but there is a feature of this theme that can create problems with a fixed-width layout. This can potentially affect any integrated setup, not just WordPress. By default, if you go to single-image view, it gives the user the option of displaying the image at different sizes. You can change the default 640×480 initial size, but that’s not the main issue of this tutorial. Just in case you aren’t sure how to do that, though, these steps are for you:

  1. Login.
  2. Go to Edit Album -> Album.
  3. In that area, you should see a section called “Resized Images.” Change the first target width row to the maximum width that will fit in your layout. Make sure that the row is “Active.” Also be sure that all of the other sizes are blank.
  4. In the “Recreate thumbnails and resizes” section, select “Recreate resized images.”
  5. Save the changes.

My understanding is that you’ll have to repeat this process for all sub-albums. As far as I know Gallery2 has no provision for applying the changes to all albums below the parent album. So, click on each album to open it, and then repeat the process from step 2. UPDATE: It looks like that feature has been added since this post was first written.

Even after this change, another problem persists. This brings us to the main point of this tutorial. When viewing a single image, a user has the option of viewing the image full-size. The problem is that the full-sized image is displayed inline with the layout. So, if the width of the image is larger than the width of your layout, the image will extend beyond the intended bounds of your layout.

I checked the Gallery forums to see if there were any solutions to this problem. There weren’t, so I started a new thread. Here is the first reply:

mindless writes: siriux theme shows the resize and a link to download the full size. PGtheme (documentation/user contributions) has an option for showing full size in a separate window. you can learn from these examples and modify matrix to behave however you like :)

This is one way the solution can be implemented:

Navigate to the directory of your Gallery2 theme. Go to the templates directory of your theme (in my case /gallery/ themes/ matrix/ templates/), and create a new subdirectory in there called local. This ensures that we don’t overwrite the original template files. Gallery will use files in this directory before it looks in the main templates directory. Anyway, copy the photo.tpl file from the main templates directory into your new local directory.

In the new copy of photo.tpl (in the local directory), delete line 38:
{g->block type="core.PhotoSizes" class="giInfo"}

Replace it with the following code (taken from the Siriux theme):

                <a href="{g->url arg1="view=core:DownloadItem" arg2="itemId=`$theme.item.id`"}">
                  {if $theme.sourceImage.mimeType != $theme.item.mimeType}
                    {g->text text="Download %s in original format" arg1=$theme.sourceImage.itemTypeName.1}
                  {else}
                    {g->text text="Download %s" arg1=$theme.sourceImage.itemTypeName.1}
                  {/if}
                  {if !empty($theme.sourceImage.width)}
                    {g->text text="(%dx%d)" arg1=$theme.sourceImage.width arg2=$theme.sourceImage.height}
                  {/if}
                </a>

Or, if you want the image to open in a new window (compliant with XHTML 1.0 Strict), you can use this code:

                <a href="{g->url arg1="view=core:DownloadItem" arg2="itemId=`$theme.item.id`"}" onclick="window.open(this.href); return false;">
                  {if $theme.sourceImage.mimeType != $theme.item.mimeType}
                    {g->text text="Download %s in original format" arg1=$theme.sourceImage.itemTypeName.1}
                  {else}
                    {g->text text="Download %s" arg1=$theme.sourceImage.itemTypeName.1}
                  {/if}
                  {if !empty($theme.sourceImage.width)}
                    {g->text text="(%dx%d)" arg1=$theme.sourceImage.width arg2=$theme.sourceImage.height}
                  {/if}
                </a>

If you copy and paste that code as it is, the proper indenting should be preserved. That’s why the spaces are there.

I hope this helps someone. As always, if it does, it would be great to hear from you. If it doesn’t, it would also be great to hear from you so we can work out why it’s not working.

24 Responses to “Is Gallery2 Breaking Your Layout?”

  1. 1
    Your Drunken Mom Says:

    Nice tips! I was wondering though, how do you get rid of the right navigation bar when viewing the wp-gallery2.php and getting the embedded gallery to stretch to fit where the nav bar was?

  2. 2
    Dan Says:

    For your site… Try this… Navigate to your Gallery2 templates directory, and open up theme.css … add this line at the bottom:

    #maincol {
      width: 97% !important;
    }

    What that’s doing is overriding your WordPress theme’s definition of #maincol, making it stretch out more. Hopefully that will help, but if not, lemmie know.

  3. 3
    Your Drunken Mom Says:

    It didn’t work at first because the #navcol id was set to 25% width, so I fixed that also. Thank you for the idea of doing that!

  4. 4
    Sammy Russo Says:

    I’m working a photo gallery for a client of mine. Your fix to set full size images to open in a new window worked perfectly. Thanks. I’m still working on setting up the photo gallery… once completed I’ll be embedding it into our WP Blog… blog.aorafting.com.

    Thanks again for the tip!

  5. 5
    Dan Says:

    Aw, thanks for commenting! That’s really nice of you.. Your WP installation looks nice and is well-customized… I’m glad the new-window code helped!

  6. 6
    Tom Says:

    I’m a drupal user but the same issue/fix applies for my theme as well. Leads me to wonder, how many folks use Gallery 2 embedded vs. standalone? Seems like this is something that should be incorporated into it.

  7. 7
    Dan Says:

    Good point.. It seems like enough people would have it integrated. I think that the WPG2 people have some templates available. I haven’t used them, so I’m not sure if they incorporate this sort of solution. Thanks for your comment!

  8. 8
    Jeff Says:

    Thank you - very very helpful!

  9. 9
    Dan Says:

    I’m glad it was helpful :-)
    Thanks for commenting!

  10. 10
    Brian Says:

    Thanks for the tip…very helpful.

  11. 11
    Dan Says:

    Thank you for commenting :-) I guess most of the time, if these things are helpful, people don’t comment. But it’s nice to see when it is being put to use.

  12. 12
    Shayne Power Says:

    Might be an old post, but I have just found it, and found it to be very useful. (Along with this)

    Thanks very much.

  13. 13
    Steve Robinso Says:

    Thank you so much for this. I spent hours on the Gallery website, only to finally find your post, with your link. I am also grateful you have kept this post active.

  14. 14
    naisioxerloro Says:

    Hi.
    Good design, who make it?

  15. 15
    Dan Says:

    Thanks,
    http://soulpass.com/daniel-upshaw/

  16. 16
    Brock Says:

    Very helpful, thanks.

  17. 17
    Graham Says:

    this worked for me, thanks!!!

  18. 18
    Dan Says:

    Nice! Glad it worked for you guys!

  19. 19
    Seul Says:

    Thanks mate. Works great!

  20. 20
    Dan Says:

    Cool :- )

  21. 21
    Abramovicl Says:

    Hi , i have some questions about you desing
    maybe you can give designer contacts?

  22. 22
    Dan Says:

    Do you mean the design of this website, or the code in this post? The website is pretty old and the code could be a helluva lot better, but I could probably answer questions about it…

  23. 23
    relegated Says:

    Thank you, this took care of what I wanted. However when I change permissions on the default gallery group so everybody can’t see the original image the %s doesn’t work. Can you tell me how your permissions are set or how I can get the %s to work without having them be able to view the original image in Wordpress?

  24. 24
    Chris Says:

    Hey thanks a lot for your post, it works like a charm! :-)

Leave a Reply