by Karl Bunyan

Programming, PHP, JavaScript, .Net, motorbikes, pubs, poker, football, news, restaurants and anything else


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

<category text="Programming" />

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 <category> 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

<%@ Page language="c#" Codebehind="index.aspx.cs"
AutoEventWireup="false" Inherits="blog.index" %>

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:

<bloggerPost><postTitle text="<$BlogItemTitle$>" />
<postDate text="<$BlogItemDateTime$>" /><$BlogItemBody$></bloggerPost>

And is wrapped around your existing </bloggerPost> 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:

<asp:Literal id="categoryList" runat="server" />

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 <category text="Category name" /> (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 <error> 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

Link to this post


Thanks! This is what I've been looking for (but seems complicated!?)

posted by Blogger Andy Hardy : August 01, 2005 2:42 PM  

It is! As your blog is on Blogspot it probably won't work anyway... It's definitely the techie's approach.
posted by Blogger Karl Bunyan : August 01, 2005 2:44 PM  

and what about carterbloger, still no release?
posted by Anonymous Anonymous : November 22, 2005 7:08 AM  

I have another simple yet effective way to enable categories in your Blogger blog. It does not require tagging to external sites, and takes 5 minutes to set up. For step-by-step instructions, please see http://netcf2.blogspot.com/2005/11/blogging-categories-categories.html. Hope you like it.
posted by Blogger danchong : November 24, 2005 5:06 PM  

Post a Comment

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!!!

Link to this post

Post a Comment

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.

Link to this post

Post a Comment

Avoid being shot on the tube

This photo was apparently taken at Tower Hill tube station today and gives some good advice about how not to get yourself shot on the tube:

Link to this post

Post a Comment

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

Link to this post

Post a Comment

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!".

Link to this post

Post a Comment

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

Link to this post

Post a Comment

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'.

Link to this post

Post a Comment

The war on terror, UNIX style

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:

A rare photo of Deborah without her hands in front of her face:

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:

Link to this post


Hey Karl, I take my hat off to anyone who intentionally jumps out of a fully serviceable aeroplane!

Well done mate,

Andy :-)
posted by Blogger Andy Hardy : July 25, 2005 2:55 PM  

Post a Comment

More London bombs, ho hum

So, we have more disruption resulting from a (luckily) failed attempt to blow up more parts of the tube. It did seem fairly inevitable that there would be a second attempt, as much as it was inevitable that someone or other would eventually manage to pull off the first one (whatever cause they claimed it was in aid of). For me, living with the possibility of a terrorist attack is just something that comes part and parcel with being in London, and I've made the choice to stay here that the realisation of that possibility isn't going to change. After all, statistically the risks are still very small. For some people I can imagine this might tip the balance the other way, though, and I've yet to say whether I might find myself cycling in Central London slightly more often. (You never know - there might be more lives saved through people actually getting some exercise!)

If they're going to keep blowing things up, though, it's going to start getting really annoying. Hopefully there isn't an endless supply of idiots who are prepared to strap bombs to their backs, or at least the idiots will carry on being stupid enough to not be able to work their bombs.

London blasts: At-a-glance
Tube travel disruption continues

Link to this post

Post a Comment

When articificial intelligences collide: Eliza vs Eliza

This conversation set up between two Eliza clients is quite amusing. I didn't really know about it before, but Eliza appears to be a computer therapist. It doesn't seem to do a particularly good job of analysing itself.

Eliza vs Eliza
Eliza the computer therapist

Link to this post

Post a Comment

Hot day in London

It is so hot today and after having a busy morning the heat has finally driven me insane and I feel just like the picture below:

Banging my head on my computer

Link to this post


Broken img link? No good for me in Safari.
posted by Anonymous JB : July 13, 2005 4:28 PM  

Ahhhhhh. That's better.
posted by Anonymous JB : July 13, 2005 4:31 PM  

spot on!
posted by Anonymous Anonymous : July 15, 2005 10:07 AM  

Poms are never satisfied --- first it's too cold; then when the weather gets better... it's too hot!?!?!?

Andy :-)
posted by Blogger Andy Hardy : July 15, 2005 6:08 PM  

Post a Comment

William IV pub, Leyton

For anyone in the area who doesn't already know about it, the William IV pub at the Baker's Arms in Leyton is one of the best pubs in the area. They have a good selection of real beer such as "London Pride" and "Discovery", and serve surprisingly good Thai food. There is a small beer garden out the back which was fairly empty on a Tuesday night.

The only real way to get to the pub is by bus, either from Walthamstow, Stratford (69), Leyton (any number of buses), or from the centre of town on a 48, 55 or 56.

William IV on Beer in the Evening
William IV on Fancyapint.com

Link to this post

Post a Comment

Blogger adding an extra clear: both div to posts

Lots of people have noticed recently that Blogger has started publishing posts with a <div style="clear: both"></div> tag before the posting text. This broke my layout and have me invalidly nested tags since I was including the opening and closing <p> tags in the template. The extra <div> tag meant that the browser closed the previous block element (the <p>) and then after closing the <div> went back to put the first paragraph of content straight after. This meant my posting class wasn't being applied so the first paragraph of every post didn't look right. It also broke the already broken HTML on the site.

So, since it was annoying for me, I've written a partial fix in JavaScript. Paste the code below into your Blogger template just before the closing </body> tag. This is important as it needs to be in the code after all the content.

<script type="text/javascript">
var allDivs = document.getElementsByTagName("div");
for(var i=0;i<allDivs.length;i++){
 var curDiv=allDivs[i];
  var block=curDiv.parentNode;
  html=html.replace(/(<\/p>)?<div style="clear: both(;)?"><\/div>/gi,'');

I've tested it in IE6 and Firefox so far, and I'm not really bothered about the rest at the moment although it should work in IE5+.

Link to this post


Okay - adding a comment to my own post, it can be turned off within Settings -> Formatting and change 'Enable float alignment' to 'No'.
posted by Blogger Karl Bunyan : July 12, 2005 11:47 AM  

The original solution is better.
posted by Anonymous Bealers : July 18, 2005 5:53 PM  

Post a Comment

Review of Nama Bar and Restaurant, London (kangaroo and chips)

I went to the Nama Bar last night on a special offer (vouchers from The Times) since I'd been in a pub in the area. It's not quite what I was expecting, definitely more of a bar than a restaurant, and not very Japanese at that. Okay, there were the usual Bento Boxes (which seemed to contain a slightly odd combination), but otherwise there were things like Cumberland sausages and mash. Just adding wasabi to mash potato doesn't seem particularly Japanese.

Feeling adventurous, I decided to go for the ostrich (which I have had before). I wasn't quite feeling adventurous enough to try the crocodile, but only because it came with wasabi mash which sounded a step too far to me. Unfortunately they had no ostrich but I was offered kangaroo instead. Definitely a result there! Kangaroo seems to sit somewhere between lamb and beef both in flavour and texture. A side portion of french fries were definitely a necessity, though. Plus a glass or two of red wine. The prices seemed reasonable to us since we were on a 2 for 1 offer, but I would expect a meal to come to around £25 a head at full price which isn't too bad for good food in central London.

Would I go again? I would be more likely to go for the drinks than the food, to be honest, not because of the quality (I actually found the food to be quite good) but because the atmosphere doesn't seem quite suited to that level of eating. The music was a touch on the loud side and the whole place had a bit more of a 'party' feel to it all. Also, I was sat on a sofa which wasn't quite high enough for the table.

The Nama Bar website
Location of the Nama Bar
Nama Bar details at View London

Link to this post

Post a Comment

A Letter To The Terrorists, From London :: The London News Review

This letter to the terrorists from London pretty much sums up the way most people feel about the tube and bus bombings yesterday.

Link to this post

Post a Comment

London transport bomb attacks

Luckily my travelling today didn't overlap with any of the explosions, as my office is about half a mile outside of Liverpool Street, but it's certainly causing a lot of disruption. No-one I know seems to be that badly affected either except for having to walk home.

It will be interesting to see how the country reacts in view of other terror attacks around the world. Terrorists attacking New York prompted America to invade half of the middle east, bombs in Madrid changed the result of the Spanish election and caused withdrawals from Iraq, so I wonder how much of a difference it will make here. My personal view is that in terms of general public opinion it won't make much of a difference. As a nation we may easily roll over in the face of America's warmongering but a positive quality is that we are not generally prone to reactionism, either to become more agressive or to change the way we do things just to placate these people. London is generally multicultural enough to know that the actions of a small group of extremists does not represent how larger groups think in general, and really I can't see how carrying out these attacks is going to do anybody's cause any good whatsoever.

London rocked by terror attacks
Travel chaos after London blasts

Link to this post

Post a Comment

BT's useless customer support

This was received by one of our clients as a response to mail server queries directly from BT customer support.

BT Yahoo muppet customer service drone

Link to this post

Post a Comment

London to host Olympics in 2012

London has won the contest to host the 2012 Olympics, which is great news for all of us who live in East London and have been waiting for some infrastructure investment to give the area a lift for years.

Victory is particularly good given that it was the French that lost, of course, given Chirac's recent behaviour over food and EU subsidies. This BBC article particularly rubs it in.

Some of my favourite quotes from news articles include:

But raindrops began falling on disapointed Parisians outside the Hotel de Ville in the French capital shortly after the result.
Chirac spoke passionately to the IOC, saying, "The heart of Paris and the heart of France are beating in unison in the hope of becoming Olympic host in 2012," The Associated Press reported. "You can put your trust and faith in France, you can trust the French, you can trust us."
To those who see the French president as out of step with the pace of modern Europe, Jacques Chirac's jibe about British food is perhaps a case in point.
They've got a slick rail network, a home-grown car industry and magnificent stretches of Napoleonic architecture that escaped the German Luftwaffe's mighty payloads.
We, on the other-hand, have half their unemployment, a global language and, for the next six months at least, the EU presidency. Oh, and the 2012 Olympics.
Appropriately, the celebration party is being held in Trafalgar Square, a week after celebrations marking Nelson's famous victory over the joint French / Spanish fleet 200 years ago.
This decision will exacerbate that general sense of malaise, especially as the winner is Paris' greatest rival, London. President Jacques Chirac had wanted to arrive for the G8 summit a winner. Instead he comes as a three-time loser whose nation was pipped at the post by a victorious Britain.

My heart bleeds.

Paris 2012 Olymbic Bid T-shirts half price

The Olympic bid voting results
London beats Paris to 2012 Games
More disappointed French comments

Link to this post

Post a Comment


Current Posts

Other links

Change the background image