Blogger Labels

I have used Blogger for a good few years now to publish the news content on our site. A while back they changed the way several things worked, and added a new feature: labels. I was pretty wrapped about the labels as finally I could have the 'in category' style posting I'd wanted for ages. It's taken me a while to activate the labels as I've been busy doing other things, like travelling. So when I found that I could not display the labels because I publish via ftp to my own host I was pretty annoyed.

No support from Blogger

A quick search of Bloggers help and the internet soon informed me that Blogger are unlikely to support the label function for ftp sites, ever. Bah, says I, and many other people out there. Quite a lot of people out there have rolled their own solution to the problem, using a variety of approaches.

My solution

Being a nerd I decided to have a crack at it myself, and here is the result. It is a small PHP script that generates a javascript function that will, when invoked, find an element in your page and replace the html content with a html <ul> list of links to the labels pages. You are free to style that list however you please.

Version History

Download It

Download the latest version here bloggerlabel1.1.zip

How to use it

Just follow these simple steps. It assumes your web server is PHP capable and is running 4.3.x or higher. I am also assuming that because you're looking at this you know a bit about html, css, etc.

  1. FTP the script bloggerlabels.php onto your web server
  2. Add the following to incldue the script within the <head> tags of your page. Make sure you change the path to the script to match where you placed it on your server. <script type="text/javascript" src="/js/bloggerlabels.php"></script>
  3. Add a <div> block on your page where you require the list. You might want to use this <div id="labels">No Topics</div>
  4. Add this at the bottom of your page, before the closing </html> <script type="text/javascript">populateLabelsDiv();</script>

Changes you might need to make

These are a few changes you'll need to make to the script so it works with your site. There's no getting around this, it will always need some site specific information. For ease of use the four values required have been placed at the top of the script.

  1. The first value to change is the ID of your blog entry. In your blogger template each blog entry is most likely surrounded by a <div> tag, which has an ID attribute. The script uses that ID to count up how many blog entries are in each label file.
  2. The second value to change is the ID of the <div> tag that will contain the label list. If you have used the example above there is nothing to change, but you might want to change it fit in with your css.
  3. The third value to change is the sort type you want to have. This can be either title or count. This controls whether the sorting is done by title, or the number of times the label occurs in your posts.
  4. The last value to change is the sorting direction. A value of true will sort the labels in ascending order. A value of false will sort them in descending order.

Thats it. You should see a list of labels, something like this

Troubleshooting

I'll add common problems here if people are having problems. If you want to ask me a question, or leave a comment you can email me at the following : work [at] mlbm.co.uk.

Support a code monkey

If you are feeling generous and have read this far down the page perhaps you'd like to throw a few pennies in my virtual hat. Donate through paypal by clicking on the button. Thanks !