Adding categories to Blogger blogs

27th September 2005 update

I’m trialling a new piece of software called Caterblogger. It will add categories to any Blogger blog. You can register interest in it on the site.

The original post follows below:


Blogger is really ease to use and set up, and manages individual posts really well. It’s also useful to be able to send posts in by e-mail, and there are quite a few different ways of configuring how posts are displayed. With some HTML knowledge, the template can be made to look exactly how you might want it. It also manages things like archiving particularly well, and the way posts are published with filenames matching the page title (mostly) is really good for being found in the search engines. What it doesn’t do, though, which would be really useful, is to allow posts to be put into categories. I was keen on implementing it on this blog, however, and thought that with a bit of code I could work it out. So I did, and the results can be seen on the right hand side of the page under the ‘Categories’ heading.

It’s not exactly straightforward, though. To get it working using the method I’ve used you’ll need the following:

  • A blogger account (duh)
  • Your own hosting that supports ASP.Net pages, where you can also change file permissions to allow IIS/ASP.Net to write to the file system
  • To get it working without recompiling, the pages will need to be served from the web root (since I haven’t bothered adding anything to web.config, which I really should do…)
  • Some knowledge of ASP.Net and preferable C#
  • The ability to edit your own blog’s HTML templates
  • Not be afraid of embedding XML in your posts, and troubleshooting errors
  • To customise the category layout: knowledge of CSS and, preferably, XSL

So, it’s not for the unprepared. I mean it – without a fairly good idea of what you’re doing, you’ll probably end up doing more harm than good. (I’d recommend installing it all locally first either way.) I’m also unlikely to be much help if something doesn’t work, so this is all at your own risk.

The principle behind my Blogger categories

I’ve written the code to make it as simple to put posts into categories as possible once the template has been set up. A post is put into a category by placing an XML tag into the posting text. The format of these categories is


Once a new post is published it is posted to the homepage of your blog by Blogger. My code registers that the blog content has changed and parses through all of the postings in the various subdirectories (by looking at files in subdirectories ending in .aspx and not containing the word ‘archive’ in the filename). It looks for the

tags and pulls out all of the category names that are contained in it and builds a new XML document containing a list of all of the categories and all of the files that are within each category. Each post can be in multiple categories.

The advantage of this is that categories don’t need to be set up beforehand – as soon as a post is published in a category, that category is created. The downside is that you need to make sure you spell the categories consistently.

Setting up Blogger categories

The files that are needed are in the zip file which you can download here. You’ll need to make sure that either IIS or the ASP.Net process has write permissions to the root of the blog, depending on the user that IIS is being. If you get a file permission error and change web.config to show you what’s going on then you’ll see which one you need to set up. Otherwise, as these files are, if deployed correctly onto a new web application at root level they should work straight out of the zip. However, you’ll get my blog content (as captured at a point in time since index.aspx is not going to update) with links to my images. If you get a compilation error at this stage then fix it now before you go any further. (Possible errors would include file write permissions or path problems. Anything else may be more serious.)

Once the code runs without your blog being connected to it, what you need to do to get it working is:

  1. Add code to your own Blogger template
  2. Update the HTML of postsByCategory.aspx to suit your own blog
  3. Change your Blogger settings to publish all files out as .aspx
  4. Add category XML to your posts
  5. Republish each post of your blog
  6. Check for XML errors and tidy up
  7. Update the category listing XSL files to match the look and feel of your blog.

1. Add code to your own Blogger template

Firstly, the page needs to be made a true aspx page. Add


to the top of the page.

Next, the category list and other information needs to be generated within each post. A small piece of code needs to be added to your posting body. This looks like the following:

" />
" />

And is wrapped around your existing tag.

What this does is wraps the whole post in an XML block (this will create invalid XHTML, but Blogger does that anyway most of the time) and add some extra information such as the title and the date of the post as XML nodes containing Blogger tags.

You’ll also need to add an asp:Literal to your template to display the categories list. This is a simple tag which can be added wherever in the HTML you want the category list to appear:


2. Update the HTML of postsByCategory.aspx to suit your own blog

postsByCategory.aspx is a standalone file so updating it should be an easy HTML job. You shouldn’t need to change any .Net code

3. Change your Blogger settings to publish all files out as .aspx

See my previous post Publishing with aspx extension from Blogger.

You’ll also need to change the post timestamp format to English date, e.g. 27.07.05 (for 27th July 2005), as this is used for ordering posts (in reverse date order) in the category list. This is found in the Blogger console -> Settings -> Formatting as Timestamp Format.

4. Add category XML to your posts

As mentioned earlier in this post, to put a post in a category you just need to type

(where ‘Category name’ is the name of the category you want to appear) in your post. This can be anywhere within the text of the post. I tend to put it at the beginning so it’s easier to find, but it doesn’t really make any difference.

5. Republish each post of your blog

This is a pain but it’s the only way to get each file published as an aspx file. You’ll need to do it if you’re putting your posts in categories in any case. Each post will need to be republished individually – you can’t do a ‘Republish all’.

6. Check for XML errors and tidy up.

Once you view any page on your blog, a file called categories.xml will be published in the web root. Download this and open it up in a text editor or any other viewer. As well as category nodes, there are likely to be a number of nodes – these show which files contain invalid XML in the posts so you should take a look at them and try and fix the error. The code has been written to skip any errors so you should get a category list generated as long as at least one post is valid. The file should be generated regardless since it also contains error nodes. Errors are often caused by invalid characters in post bodies (e.g. pound symbols not being inserted as character codes) or, slightly more annoyingly, double quotes in post titles (since the post title is contained in an attribute node in the template in our little XML block).

7. Update the category listing XSL files to match the look and feel of your blog.

This should be fairly straightforward even if you don’t know XSL well, just don’t break the templates. The HTML is very simple and you may even be able to get away with just changing the CSS instead.

That should be it

In theory, that should all work. In practice, I’m willing to be about 75 things have gone wrong so far and now you wish you’d never started. For the really keen (or more likely for bug-fixing) you can download all the source files here (and let me know if anything’s missing). Best of luck!

Download the Blogger categories compiled files
Download the Blogger categories source files

My new Sony Ericsson K750i

I’ve just upgraded to the new Sony Ericsson K750i phone and am well pleased with it. It works well as a phone and is much more responsive and easier to use than my old Nokia 6600, but it’s all the extra features that make it really great. The camera takes pretty good pictures for a camera, let alone a phone, and the way it comes straight on when you open the back cover without having to unlock the phone makes it very useable. There’s also a pretty good LED for giving some light at night which gives pretty good results. I also found the bluetooth connection to both my PC and my Clie quite easy to set up and plugging the usb cable in just mounts the memory stick as a drive on the PC which makes copying files from one to the other very easy and fast.

After using the 6600 I found the interface much better and I can’t imagine I’ll go near another Symbian phone again in a hurry. On the K750i I press a button and it responds; there’s none of the delay the 6600 had. The text messaging is also much easier as you get a dropdown with predictive matches as you type, and can manually choose any letter you like at any time without having to go into a separate ‘spell’ mode.

It’s saved me having to buy a separate digital camera and mp3 player, and has an FM radio included too. Brilliant!!!

Publishing with aspx extension from Blogger

I wanted to publish my blog with something other than the .html extension and after some experimentation and hunting around I found this:Blogger Forum – Forum

The way to do it is to change the main page extension (from index.html to whatever, e.g. index.aspx) and do the same with the archive page. Then you need to go into each post individually and re-publish it. It’s a bit of a pain, but does work.

A handy tip: download all of your pages (in html format) first and then re-upload them afterwards so that all inbound links actually go somewhere.

Tate Modern – Herzog & de Meuron

I went along to the Herzog & de Meuron exhibition at the Tate Modern this Sunday just gone. Although it was kind of interesting in terms of a ‘thought process’ kind of thing, it really didn’t explain much, and there was no clear train of thought to follow from concept to building which would really have swung it. If I was honest, I’d say it was more about a collection of individual items put in the same room with the hope that together they’d somehow have some kind of cohesiveness. All it really left me with was feeling sorry for the poor year-out students who have to spend all their time cutting out cardboard contours and foam blocks.

One of my favourite pieces of blurb was about ‘designing a building that looked different from every angle’. I would love to see someone design a building that looked the same from every angle; it would either have to be an omni-lit sphere, or rotate as you moved around it, which would be really annoying if you were trying to find the door.

Herzog & de Meuron exhibition at the Tate Modern

Ancient phallus unearthed in cave

Got to love this story about Ancient phallus unearthed in cave on the BBC site. One of the best things about it is the fact that they didn’t know what it was until they found the last piece. ‘…it was only with the discovery of a 14th fragment last year that they were able finally to work out the “jigsaw”.’ I have this image of a load of scientists standing around and putting the last piece of the “jigsaw” in and suddenly realising “oooohhhh…. it’s a stone penis!”.

Review of The National Portrait Gallery Restaurant

I went for lunch at the restaurant in the National Portrait Gallery yesterday. I’d already been once before, towards the end of 2000, and enjoyed it then (not least because someone else was paying) and was looking forward to going again. We booked in advance, which I think is advisable at any time.

The menu style is a bit different to usual in that you choose to have either 2 or 3 courses for either £20 or £25. Luckily, you can change your mind half way through i.e. go for a starter and then ‘upgrade’. This seems a pretty good idea, particularly when it comes to splitting the bill in a group. It also means you don’t have to feel guilty about liking the most expensive thing on the menu.

Before getting to the food, though, the best reason to come to the restaurant National Portrait Gallery is for the view out over Trafalgar Square and towards Westminster. It really is a great backdrop to eating. Another good reason to book seemed to be that booking would get you a table by the window whereas people who just turned up didn’t seem to get the same privilege.

The menu was slightly odd, I found, although I wouldn’t have thought it so odd if it hadn’t claimed to be brunch (served between 11:30am and 3pm on a Sunday). For one, that seems a bit late for brunch (picky, I know), but also none of the food seemed particularly brunch-like. Okay, fish would come with a poached egg, and the most common form of potato was a hash brown, but apart from that… I had foie gras for a starter, for example (which was very nice). The courses are all quite small too and it’s more than likely that you’ll end up with three if this is the main meal of the day. Two courses was okay for lunch, with a couple of glasses of wine as well, but for an evening meal I think a dessert as well would be essential.

The food is all well presented (made easier by being smaller portions so plenty of room for layout, I suppose…) and generally the whole experience does feel quite up-market (for what I’d know of that). Pretty good food, a nice space, an excellent view and generally not bad value altogether.

The National Portrait Gallery Restaurant website

The National Portrait Gallery on Streetmap

Alternative take on coping with terrorism

The antidote to the ‘we’re not afraid‘ site: I am fucking terrified. Mostly just a collection of images with amusing captions expressing various degrees of terror. I like the ‘why’ section:

Terrorists cause terror. That’s why they’re called terrorists. If they didn’t cause terror, they’d be called something else – like ‘annoyingists’.

Trip to Luxembourg

I’ve just come back from the blues and jazz festival in Luxembourg. A few of us went out for the festival but also to jump out of a plane (with parachutes attached) and now I’ve managed to steal other people’s photos to upload.

The people in the photos are generally a mix of myself, Chris Greenway, Nick B, Susan Engel and Deborah Causton.

The most noteworthy part of the trip was definitely the skydive. We jumped (strapped to a ‘real’ parachutist) from a Cessner at around 10,500ft and had (I think) around 20 seconds of freefall and then a few minutes of cruising around with the parachute open. Both parts are absolutely brilliant. It cost us 195 euros, which apparently is one of the cheapest in Europe, and was from an airfield in Luxembourg just northwest of somewhere called Wiltz.

Chris, Deborah and myself having a last beer

Chris in his skydiving jumpsuit:

Chris, me and Deborah outside ‘The Tube’ bar:

Chris as a Neanderthal:

Chris being a tramp. He was a bit tired…

A cloud shaped as a woman.

Deborah and myself saluting for a last time before we make our jump.

Deborah having made it down successfully:

I think the small dot is me:

No explanation for this:

Myself and Nick B, who not only has no surname but moves twice as quickly as any other human being:

Me coming in to land on the parachute:

Myself, Susan and Chris having a last beer:

Me, Susan and Nick:

We found a witches head hanging from the ceiling so I put my head in it:

…as did Susan:

Me having landed after the skydive:

Me coming in to land hanging from the parachute:

This is the plane we jumped out of. Don’t know how we fitted five people inside:

In case we didn’t realise skydiving was dangerous, this label that was visible only from inside the plane reminded us on the way out:

Susan, Chris, me and Nick:

Susan making some important international deal:

All of us at the airfield before we jumped: