Duh Gallery: The Simple WordPress Photo Gallery Plugin

I have been looking for a simple plugin for WordPress that just displays photos that I upload. I got tired of trying out things like Gallery2 integration and stuff like that. I just wanted a simple photo gallery. No extra text, no comments, nothing. Just a photo gallery.

So, I created it myself since I couldn’t find an easy one.

Thanks to the new WP 2.0 structure for uploads generating folders by year and month, it’s nicely categorized too. Now, I’m sure there’s tons of ways to enhance/change this plugin to work better with different themes, better output, and probably faster code. But, for the sake of failing fast, I’ve decided to release it as is.

Known Issues: Yes, there is an inherent problem with using the wp-content/uploads folder in that there’s no way to distinguish between a graphic you uploaded for a post and a photo you wanted to share. The idea behind this plugin is to decipher this problem with a minimum width and height. So, there are two optional variables to the plugin when you write the code in your page; minimum height and minimum width. By default they are set to 300 pixels each. This means that if an image’s height and width are above 300 pixels, we will consider that an image you wanted to display in the photo gallery. Additionally, when the photo is displayed as enlarged, we set it by default to a width of 450 pixels wide to hopefully fit it into most themes. If you need to modify this, you can do so within the function call.

If you use it, I’d love it if you either commented or did a trackback here so I can see your implementation of it.

If you modify it, I would love to know. I would be happy to take your modifications in and re-release it with your name in the credits if the modifications are general enough to fit most everyone’s themes and needs.

Enough of the chitter chatter. Here it is: duh-gallery.zip (please go to the wiki to download it or discuss any issues with it from here on. I am not abandoning the project, just moving it to a more community supported location. Thanks!)

Requirements: You’ll need Exec-PHP or some other plugin that will allow you to write PHP into your posts/pages. You’ll also need to make sure you have WP 2.0+. Last, if you have modified the location of your uploads folder, you’ll need to change the location in the plugin.

Installation:
1) Extract the zip file.
2) Upload the duh-gallery.php file to your plugins directory (usually wp-content/plugins).
3) Activate it in the Plugins admin panel.
4) Write a new Page. Put the following PHP code inside the page (you may have to turn off the visual rich editor before entering this code by going to Users and unchecking the box “use visual rich editor” at the bottom):

<?php do_action('duh_gallery'); ?>

Optionally, you can specify the enlarged display width and the minimum width and height to be considered a photo in this gallery like this (450 is the width to display enlarged images at, 100 is the min-width an image needs to be to be shown in the gallery and 150 is the min-height an image needs to be to be shown in the gallery):

Donate to Charity: I didn’t realize how popular this would get so quickly. So, since plugins are generally free, I’d like to ask for your support to help some charities I know needs it. One in particular is called Giving Anonymously, which is just getting started. It’s mission is to foster generosity one-to-one. If you use this plugin and care to donate to a cause such as this, please do so here. (The company name will be called Property Essentials, which is my company name. But you’ll have to trust me that I’ll give the money to Giving Anonymously. Sorry, I don’t have another way around that right now.):

to Giving Anonymously

Credit: I have to give credit where it’s due. Thanks Robert, for the help on building my first plugin. This guy is a genius.

UPDATE v0.1.2: I updated the plugin already so that it displays thumbnails instead of full images resized down.

The easiest way to do it is download the PHP-Exec plugin first (see the link above), and activate that. Then, write a Page (not a Post), and put the PHP code inside that page. Then it’s automatic and it will show any photo you upload automatically.

When I activate it it blows up the site with this bit information. I have waited for a simple gallery for quite a while and was hoping this was it.

I must be doing something wrong but I did as your install info asked and uploaded the single php file duh-gallery.php file and poof. I noticed another file as well tried that in addition as well with the same result.

Yea, sorry Rick. I received this email from Tony, who said he fixed it. I’m not exactly sure why this works for him. But, here you go:

Hey man, I fixed it. I edited your main comment. I removed the “?>” in “Just paste < ?php do_action('duh_gallery'); ?> into the page you want to use as your photo album… ” My page was reading it at the end of the PHP script, instead of reading it at part of your comment. Once I removed it, uploaded it, it worked great.

What can I say, I love my “clients”. :) Call me a fanatic. BTW, if you need hosting, I’m just as fanatical about my hosting clients too. The design of the site sucks and is very outdated, but I like to spend my time with my clients and doing other things that matter more.

Thanks for your support Rick, make sure to let me know if that helped.

Well it was a nice try but that didn’t work. It still blows up upon activation. Same thing as before. I removed the entire just paste code as well. It’s commented out properly but to no avail. Anymore ideas?

*Note* I’m emailing you now to see if there’s a better way I can help you via IM and/or taking a look at your site a little closer. I want to make sure we figure this thing out as I haven’t been able to see the problem on my own sites yet.

Hi Nate
Have tried your plugin. Running it on a wp 2.0.2 installation with no modifications made, gives me the following error:

Photos
Warning: opendir(/hsphere/local/home/srjma/news.consits.dk/wp-content/uploads): failed to open dir: No such file or directory in /hsphere/local/home/srjma/news.consits.dk/wp-content/plugins/duh-gallery.php on line 142

Warning: readdir(): supplied argument is not a valid Directory resource in /hsphere/local/home/srjma/news.consits.dk/wp-content/plugins/duh-gallery.php on line 143

Warning: closedir(): supplied argument is not a valid Directory resource in /hsphere/local/home/srjma/news.consits.dk/wp-content/plugins/duh-gallery.php on line 155

I wonder if your upload directory is not already setup. My guess is that it’s not. You’ll want to make sure to set that up first. Here’s the steps:

1) Go to your admin section » Options » Miscellaneous

2) Make sure you have something like “wp-content/uploads” in the field named “Store uploads in this folder:” (Additionally, it would be good if you checkmarked the box “Organize my uploads into month- and year-based folders”

3) You need to go to that directory (wp-content/uploads) via some FTP program (probably the same way you installed the plugin) and change the permissions to 777. How exactly you do that depends on the FTP program. But, essentially you need to make sure the owner, group and everyone can read, write, and execute in that directory.

Once you have all that setup properly, or if you have trouble doing that, let me know. I’d be happy to take a closer look.

Thanks for making this – looks like it might be exactly what I’m after.

I’m using version 0.1.2 on wordpress 2.0.2. I’ve modified it to point at a different folder, and it seems to work fine except it only shows four of the images in there. I haven’t set a minimum size for display. Bit confused. Any ideas?

It defaults to only showing images that are greater than 300 pixels wide and 300 pixels high. So, if the images you are using are smaller than that, you’ll want to set the height/width to something else.

Also, I’d suggest getting 0.1.4, but I understand if you’ve mod’d an older version. You can see what updates have been done to the newer versions above.

A bit confused about the version. I only downloaded it today, using your link above to the zip file, which I would have thought would be pointed at the latest version. Have double checked though and I definitely have v 0.1.2. Does your link need updating?

Nate already mentioned this in an earlier post, but he wanted me to post as well. I was receiving, “Parse error: parse error, unexpected T_ELSE in /home/chasaarn/public_html/
guybearinit/wp-content/plugins/duh-gallery.php on line 109″.

My problem was corrected when I noticed in my editor that the PHP script was being read incorrectly due to a PHP script example in the main comment. I removed the ending tag “?>” from “Just paste <?php do_action(‘duh_gallery’); >” Uploaded the edited version and the gallery is working fine.

Other that the above, I followed the installation instructions given by Nate on the site.

A couple of things. If you take a look at:http://www.cregy.co.uk/snow-in-lostwithiel/
You’ll see I have now added several more galleries. But the styling doesn’t look so good.
I have tried this:
#duh_gallery_photos a:link {
display: block;
}
#duh_gallery_photos img {
border: 0;
margin: 2px;
}
.attachment {
display: inline;
}
Any ideas please?
And I also thought you would be interested in the pictures about Jesus.

Hi Nate, I just can’t get the gallery to work, i’m using worpdress 2.2.1 and whenever I add the code to a post, with or without the visual editor it still just displays it as text, I do also have phpEXC activate, so I have no idea what is going on.
I also tried to make a page with the template photos and added the code into that, however I get nothing?

Hmm.. It looks to me like the Exec-PHP plugin isn’t working. Did you just download it? I’d try something else, like

<?php do_action('duh_gallery'); ?>

If that doesn’t work, then it has to be the Exec-PHP plugin. I’m not sure why it would do that – but let me know if it is. Perhaps I can help you more with your blog or ftp credentials. If so, feel free to email me.

If it prints out the code, then Exec-PHP isn’t working correctly. But, if it prints out ‘hey there’, then the Exec-PHP plugin is working properly and it must be something else. Keep telling me what’s going on with it. I’ll help you as much as I can.

From my reading of your code, you define a thumbnail filename and display it if it exists. If it doesn’t exist, you don’t create a new thumbnail file with that filename, instead you ship the full-sized image to the browser to be displaye within a thumbnail’s space… in which case, the update line quoted above is incomplete or misleading. In my case, 25 quarter-meg JPEGs, even over a 10base LAN, made it obvious. I’ll be looking into invoking ImageMagick’s convert to generate the thumbnails, myself, but that’s Yet Another Dependency — Your Hosting May Vary.

Yes, you are correct. The reason I don’t have the script create the thumbnail is because theoretically WordPress should be doing that itself. However, you’ve got a point in the sense that I probably should have one created if it’s not already there.

Thank you. That way, your script will ship thumbnails even when the pictures are SCP’d or FTP’d into place (which is how I have things arranged), rather than uploaded through WordPress (something I admit to not having tried out).

Here is the link to my site: Gallery. I like the plugin, but when it opens the first directory, it shows 2 image placeholders and there aren’t any images to show in that place. Any idea why that could be?

That sounds like the same problem as Rick had (above), just a different line. To fix it, they he said he didn’t put the “?>” in the code that you write into the page. Let me know if that fixes it for you.

I looked at the code and there does appear to be a stray “ELSE” statement on line 149 that’s causing this error: Parse error: syntax error, unexpected T_ELSE in /home/itgurlf/public_html/blog/wp-content/plugins/duh-gallery.php on line 149

I looked at the code as well, and don’t find that stray “ELSE” anywhere. I’ve even got a working copy of it running here (WP 2.0.2).

I wish I could fix it, and if someone has, please feel free to send me an email (nate [at] perfectspace . com) and attach your fixed copy. I’ll be happy to check out the differences and include the fixed copy here for download.

Oh, and Debbie, there’s no extension for a page… you create the page in the wordpress system (on the menu go to Write -> Write Page) and can name it whatever you want. And yes, after you install the php-exec plugin, you just type the line as per the instructions above, that’s the only thing to put on the page.

I have tried everything. I upgraded my site to WordPress 2.1. I have the following environment:

1) duh_gallery.php is in: /public_html/blog/wp-content/plugins
2) the following directory structure exists:
/public_html/blog/wp-content/uploads
3) I created a page through WordPress and copied the code into that page. (BTW, don’t have a clue where that page ends up in the WordPress hierarchy.

mr nice ash might be right, although I can´t see why this happens.
I added a few linebreaks to find that “missing or wrong” else statement but I found nothing.
Then I uploaded the file with my linebreaks in it and I could activate the plugin.

Hey guys, sorry that the comments you left got caught in spam, I just found a bunch this morning and released them.

Anyway, the plugin sorts the folders in descending order. Since it was intended to use the WP 2.0 structure (year, month, day), it sorts where the most current would come up first. I believe the files are sorted by the date/time they were uploaded in descending order too, if I remember right.

I had one more problem in the “showDirectory” function the
$ignore = array( ‘.’, ‘..’, ‘cgi-bin’ );
$dh = opendir( $directory );
were somehow in the above comment so I had an invalid readdir() and closdir() source
but UPDATE v0.1.7 solved it

Sorry, Nate. That was a type. My new page created through the Manage Pages feature of WordPress is displaying this:

on the page when viewed. What is wrong with the code? I also looked for the “view with richtext editor” checkbox like you mention in your instructions, but do not see that anywhere on WordPress 2.0.2 page.

i just downloaded 0.1.7, however, i opened it with my text editor and found out that $ignore = array( ‘.’, ‘..’, ‘cgi-bin’ ); and $dh = opendir( $directory ); falls at the same line as the comment on line 148. this causes nuelle’s problem on showDirectory function.

if i uploaded and activated 0.1.7 without opening it first with my editor, the plugin will work fine. but once i opened it, it returns the error on showDirectory.

Here’s one for the suggestion box:
Include any JPEG or IPTC captions that may appear in the image. This way the viewer can have an idea of what the picture is about. ImageMagick’s ‘identify’ or ‘rdjpgcom’ can be used to extract the comments.

mr nice ash,
ok, that’s just strange. I have no idea why that error would come up after opening it unless your editors are setting line endings differently. I’ll double check the formatting that my editor uses and the line endings it uses, but that’s just wacky.

nuelle,
I have not found the fix for the PHP5 problem yet. I’m having a friend (Robert Deaton, genius whiz kid) take a look at it to see if he can fix it since I don’t have a PHP5 environment to test anything in, and he’s the one who suggested I use that methodology in writing the plugin in the first place. I’ll let you/everyone know as soon as I have something. If anyone else figures it out first, I’d love to hear about it.

Seems like a great plugin… If I could get it to work. I’m having the same problem as Debbie.

On the page where I’ve added the call, I get this:

Warning: readdir(): supplied argument is not a valid Directory resource in /home/everyday/public_html/projects/KRLT/wordpress/wp-content/plugins/duh-gallery.php on line 149Warning: closedir(): supplied argument is not a valid Directory resource in /home/everyday/public_html/projects/KRLT/wordpress/wp-content/plugins/duh-gallery.php on line 156

Hi There,
Just thought I’d drop you a note to let you know I added my gallery to your WIKI and I’ve had no problems with it that I couldn’t fix easily.

I did do a couple of modifications to your script though:

added a fix to include the alt tag on thumbnails and larger images:

alt=\"$v\"

also added here:

echo '';

because without that modification my gallery page wasn’t validating
your anchor tags for the thumbnails had an extra slash at the end “/” so I removed the slash and I now have 0 warnings or errors in HTML Tidy.

What I would like to see is a mod to determine how many thumbnails to show per page. Other than that it’s a great plugin…

Hey, this is a fantastic plug-in. I’ve noticed an issue though, but it may just be on my end. I’ve noticed if a directory contains only one image, that image will not display and the page is blank. If I add a second image to that directory then both images display on the page.

Ok, I think I found what the problem is. I’m trying to use duh-gallery in conjunction with ImageManager. When I upload files to the directory that duh-gallery is configured to use, ImageManager creates a .thumbs directory that holds the thumbnails for the images. Duh-gallery is picking up this directory (even though I figure it should be ignored due to the $ignore=array variable on line 154).

I noticed in safari that my gallery page had an extra link in there, a blank in Firefox, denoted by a question mark. When I deleted the .thumbs directory that mark went away and all my images in that directory displayed. I deleted all but one, displaying was no problem.

Rightiness

I am not bound to win, but I am bound to be true. I am not bound to succeed, but I am bound to live by the light that I have. I must stand with anybody that stands right, and stand with him while he is right, and part with him when he goes wrong.

~ Abraham Lincoln

Truthiness

For myself, I long ago decided that I would rather know the truth than be happy in ignorance. If I cannot have both truth and happiness, give me truth. We'll have a long time to be happy in heaven.