Images and WordPress are a breeze these days


The Gallery

Images and WordPress are a breeze these days for most types of site, at least. The new media functionality, with the [gallery] shortcode and everything, makes it easy to add sets of photos. However, what do you do if you’re the kind of user who wants to publish hundreds, maybe thousands of photos in the long run, and you want to have a traditional photo gallery on your site? There are photo sharing sites, of course, but sometimes you just want to roll things your way, on your own site. So what to do?

Naturally, this is quite possible to do using WordPress. We’ll rely on posts and categories to create a photo gallery. First of all, name the photo gallery category Gallery, which makes sense after all. You can have several categories getting the same treatment of course, but we’ll stick to one in this example. Moving on, the idea is to have each post as a photoset on its own. So your birthday bash and all the photos you snapped while blowing out candles and opening gifts would go in one post, for example, with a proper title and even tagging. Tags are great for sorting, so you can use those any way you like. If you don’t want to mix photo gallery posts with regular posts, but still use tagging, you need to create a custom taxonomy for photo tagging. That way you won’t get a mix of posts in the various tag archives.

So how would, or rather could, it work?

So you’ve got a Gallery category and each post is a photoset. You can go about the actual content handling any way you like. The simplest way would be to just upload the images to the post and include them as a thumbnail gallery, using the [gallery] shortcode. However, if you want to you can add a description as well, perhaps as the excerpt, and then use that for browsing, feed subscriptions, and also by outputting it under the_content() in the theme file. Or you can just write it under the actual photo gallery; it is fine either way.

The important thing with the posts is that they always have images attached to them when in the Gallery category. When you upload images through the media manager in WordPress when writing or editing a particular post, it will get attached to that post. You need that connection both for the [gallery] shortcode and for thumbnail display on the category archive page, the Gallery section in this case. One more thing before you get to the code. You should make sure that your Media settings are suitable for your design and the Gallery section setup.

The Category Template

So you’ve got out posts as photo sets, each containing at least one (but most likely more) images, and you’re displaying them using the [gallery] shortcode. Now to create the Gallery section of the site using a category template file. You can tackle this in several ways, but the easiest way would be to find out the ID of the Gallery category by analyzing the URL field when editing it in the WordPress interface.

In this example we’ll assume that the Gallery category ID is 140, so your category template file will be named category-140.php. Now, in a Gallery section you’ll want to display a thumbnail illustrating each photo set (which are the posts, remember?), and there are really two ways to go about this. For control, you can just pick one of the thumbnails and set it as a custom field, showing that when listing the photo sets. However, that is another thing you’d have to fiddle with, so instead just pick one of the attached photos and use as an illustrative thumbnail that leads into the photo set.

How you want to show offyour photo sets is up to you. The code that follows is the most basic solution, just taking a traditional loop and changing how the post is displayed. Further on in this article we’ll do some cooler stuff.

Legal Disclaimer

Our website is not responsible for the information contained by this article. Webworldarticles.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.


This article was sent to us by: Juwe T. at 05132010

Related Articles

1. Creating Your Own Wordpress Template Tags
Creating Your Own Template Tags Another way to access your plugin functionality is by creating your own template tags, much like bloginfo(), the_title(), and so...

2. Things to Consider When Using the wordpress Database
Things to Consider When Using the Database The database is sometimes necessary to make your plugins function the way you want. From storing some simple options,...

3. Developing Plugins for WordPress MU
Developing Plugins for WordPress MU The process of developing plugins for WordPress MU doesn’t differ from that for traditional Word- Press plugins. The s...

4. Wordpress Plugins and Functions PHP
Plugins and Functions PHP WordPress themes and plugins usually work pretty much by themselves, coming together only when it comes to implementing features. Th...

5. When to Use Wordpress functions php
When to Use functions.php When, then, is it really a good idea to use functions.php? I have a rule for that too: only use functions. php when the added function...

6. Are you using WordPress as a CMS
WordPress as a CMS Using WordPress for things other than blogging is something that comes naturally to a lot of developers today, but not so much for the ge...

7. Things to Consider When Using WordPress as a CMS
Things to Consider When Using WordPress as a CMS So you’re considering using WordPress as a CMS for a project huh? Great, and probably a good choice too...