Creating a Photoblog with Textpattern, part 1
I’ve seen a number of questions on the Textpattern forum that suggest new users are attempting to build photoblogs, and failing – or at least choosing unnecessarily complex methods. By “photoblog”, I’m referring to the kind of layout used by many of the more popular examples of the genre, like Chromasia and Heather Champ: one image per page, with previous/next navigation linking the images in a chain.
Textpattern has a built-in “article image” feature that’s ideal for this kind of blog. As the name suggests, it lets you associate an image with each article. The advantage of using an article for each image rather than an image gallery is all the Textpattern features that go with articles: a unique permlink URL, titles, user comments, and room for us to add a description and excerpt.
In order to structure our photoblog, all we need to do is make it display one article per page. The usual method of achieving this is using <txp:article limit=1 /> on the main photoblog page, with <txp:older> and <txp:newer> for navigation.
Unfortunately, there’s a drawback to using the <txp:older /> and <txp:newer /> tags. “older” and “newer” are intended for paging through lists of articles. The main list page (http://example.com/ or http://example.com/section/) is page 1. Clicking on “older” takes us to page 2 (http://example.com/?pg=2 or http://example.com/section/?pg=2), and so on. This means that the content on each page changes each time we post a new article: the article that was formerly on the front page is now on pg=1, the article formerly on page 1 is now on pg=2, and so on. Bookmarks, search engine indexes and link aggregators will become out of date every time we post a new article.
Textpattern also has <txp:next /> and <txp:previous /> tags, which sound more promising. These are intended for paging through single articles, which is exactly what we want. Unfortunately, they only work on article archive pages, not list pages. Even though our front page only shows a single article, it is technically a list page, so <txp:next /> and <txp:previous /> won’t work.
To solve this catch-22, I’ve written a simple plugin: zem_nav. It works exactly like <txp:next /> and <txp:previous />, except it removes the list page limitation. To use it, place something like this in an article form:
<txp:zem_link_to_prev>← prev</txp:zem_link_to_prev>
<txp:zem_link_to_next>next →<txp:next_title /></txp:zem_link_to_next>
Here’s a basic photoblog recipe using the above techniques. Make sure you’ve installed and activated the zem_nav plugin first.
Page Template
Edit the ‘default’ page if you’d like your photoblog to be the front page of your Textpattern site. Otherwise, create a new page template and name it ‘photoblog_page’.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
[..snip..]
<!-- center -->
<div id="center">
<txp:article form="photoblog_form" limit=1 />
</div>
[..snip..]
Section
You’ll need a section where archived posts will live. If you’re using a default Textpattern installation, you can use the “article” section to begin with. Otherwise create a new section, and follow the prompts to upload the PHP file and edit .htaccess if necessary. Set “Uses page” to “photoblog_page” (or “default”, if the photoblog is the main page of your site).
Article Form
Save this as “photoblog_form”, and set the form type to ‘Article’:
<txp:permlink><txp:article_image /></txp_permlink>
<txp:zem_link_to_prev>← prev</txp:zem_link_to_prev>
<txp:permlink><txp:title /></txp:permlink>
<txp:zem_link_to_next>next →<txp:next_title /></txp:zem_link_to_next>
This will display the article, followed by next/current/previous links. You’ll need to arrange the layout and style to taste, of course.
You can see a quick sample photoblog I’ve put together using these examples here.
Section
If you want your photoblog displayed on the front page of your Textpattern site, there’s nothing more to do, provided you correctly edited the ‘default’ page template. If your photoblog is to be displayed in a separate section, create your section as usual, and set ‘Uses page’ to ‘photoblog_page’.
Posting an Image
Posting an image requires two steps:

If you uploaded your image via the Textpattern image, enter the image ID number in the Article Image field. If you uploaded via FTP, you’ll need to enter the relative URI to the image file – typically something like /images/pic01.jpg.
You don’t have to wait until you’re ready to publish images before uploading them. To save time, you can upload a batch of images in advance, and post the articles over a period of time.
Next: customizing your photoblog.
7 September 2004, 04:28 by zem ·
Commenting is closed for this article.
Good work, zem.
— Matthew Kelley Sep 8, 05:08 am #
when i post a second post and i click on previous i get a 404 file not found error. the page ../default/1/first-post isn’t created, nor is the page ../article/2/second-post. what is it i do wrong?
i hope you can help me with my problem!
regards, mark
— mark Sep 9, 05:45 pm #
It sounds like there’s something screwy with your section files and/or .htaccess. More discussion here.
— zem Sep 10, 05:11 am #
— ian Sep 12, 09:53 pm #
I actually had a link to fiftymillimeter.com in an earlier draft, as an example of the use of ‘pg’ navigation.
I’ve added you to my links section instead.
— zem Sep 13, 11:44 am #
— ian Sep 15, 08:31 pm #
Thanks
— Sid Carter Oct 14, 12:10 pm #
I might try and work this idea out because I don’t like having to do two things to change one thing.
Thing thing thing thing.
— SteveC Jan 7, 11:35 pm #
Apologies for the impatience.
— Anark Feb 22, 05:44 pm #
I’ve sections and clean links disabled, if that matters.. and i’m on 1.0rc1
— riff Mar 25, 09:53 am #
— riff Mar 26, 08:49 am #
Any ideas what is causing this ?
go to www.muxton.com/photos
cheers
— Scott Apr 7, 07:41 am #
Hi,
I’m going to set up a photoblog with textpattern and wonder if it would be possible to have a few thumbnails displayed next to the main image, either the 5 most recent pictures posted or the 2 images that are directly before and after the image being viewed ?
Would you know what would be the way to achieve that ?
Thank you for any tips. And cheers!
— Lilou Mar 23, 06:46 pm #