Some simple changes I've made to Pixelpost

August 31, 2006

The two things I cover below are only a very small part of the changes I've made to Pixelpost, the application I use to power my photoblog, but I figured I'd go ahead and write them out as I've received a few e-mails asking for help regarding them.

Prettifying the URI structure

Pixelpost's URIs are ugly. Take this address for example, which links to a photo of mine:

http://justinblanton.com/photos/index.php?showimage=44

While not entirely unintelligible, it certainly isn't pretty. I wanted something simpler. Something like this:

http://justinblanton.com/photos/44

It's actually pretty easy to get this sort of structure using htaccess rules, a process I've discussed quite extensively on this site over the years.

The first thing you are going to want to do is edit your .htaccess file, which you'll need to create if it doesn't already exist. Place it in the same directory as Pixelpost's index.php file. Add the following to it:

RewriteEngine on
RewriteRule ^gallery index.php?x=browse
RewriteRule ^([0-9]+)$ index.php?showimage=$1

As you'll notice, I only concern myself here with the individual picture pages and the thumbnailed archives page (which I just happen to call "gallery"). I don't account for comments, categories, ratings, or any other such thing here, because I don't use them on my site (I currently use a pop-up for comments so the URI structure is somewhat moot regarding them; see below). However, it should be fairly simple to recreate those rules by looking at the relevant URI and the rules I've shown above. Actually, some things might not be so straighforward, like when the URI uses two or more variables. If I ever start to use any of these I'll definitely work out the htaccess rules to simplify them and will write about how I did it here. If you've a specific question, please feel free to e-mail me.

After making those changes, you need to make another small change to the index.php file. Around line 85, you're going to want to change this line:

$showprefix = "./index.php?showimage=";

To this:

$showprefix = "./";

Further changes

If you want these modifications to be site-wide, you're going to have to make some other small changes to the index.php file. For example, to get your RSS feed to link to your posts using the new URI structure, you'll need to modify the link element of the feed.

Similarly, if you use a pop-up for comments, you'll want to change the <COMMENT_POPUP> tag to correspond to the new structure (somewhere around line 920). If you don't do this, then when someone hits the comment button, comments, and then closes the comment window, the address in the address bar, which they likely didn't take notice of to begin with, will be overwritten with the old URI structure. So, if they choose to link someone to the image, they'll link using the ugly structure. The end of the world? Of course not, but I like to be consistent.

Putting HTML back into the RSS feed

I'm not quite sure why, but Pixelpost removes all traces of HTML from the RSS feed. This was unacceptable as I link a lot and hated the fact that if someone wanted to follow the link they'd have to go to the image's page and click on the "info+comments" link where they could then click on the link they wanted. Nevermind the fact that they likely wouldn't know it was a link in the first place.

In any event, the fix is about as simple as they come. All you need to do is comment out a single line, somewhere around line 800:

$body = strip_tags( $body );

That's it. The feed should still validate just fine.

You should follow me on Twitter here