
I am a bit surprised that Blogger do not have a system in place for categorising blog posts. A quick Google search on the matter reveals that it is something a lot of people want to do but there are not really any elegant solutions available. The methods that I saw before I decided to make my own system involved creating a new blog for each category, or used the del.icio.us bookmark site, which does not allow for a very attractive user interface.
I have made a system that can be used by any website to categorise pages. Here are the installation instructions:
- Add this code to any page that you want to assign a category: <img src="http://da.vidnicholson.com/blogtags.php?tag=Category Name" />, replacing Category Name with the name of the category the page belongs to. (If you are using Blogger insert this in the Edit Html tab whenever you create a new post.)
- On any page that you want a list of categories to appear add the code: <div id="tagbox"></div> where you would like the list to appear and put the code <script language="JavaScript" src="http://da.vidnicholson.com/blogtags.php?dom=1"> </script> just before the closing </body>. (If you are using Blogger enter these in the Template tab.)
Update The bold text above reflects changes made to fix a bug.
Update Support has been added for other character sets.
...And you're done. No need to setup an account or password with me, no need to install any scripts on your server; as people start to view your articles through your 'permanent links' a category list like the one to the right will be generated for you.
How it works Including the img tag in each of your posts causes a transparent pixel to be shown. Whenever that image is loaded the referrer data is captured by my PHP script and your page along with the tag specified is added to my database (root URLs and archive pages are ignored so only individual posts should appear in your category lists). There is a delay of a few minutes before the page will actually appear in your category lists while the page is added to a queue for the server to verify it actually should have the tag given (this stops people spamming your category lists). If you later decide to remove a page from a category, just remove the img tag; it may take up to 24 hours for the change to be reflected in your category lists though. If you want a post to belong to more than one category, just use more than one img tag. For this to all work correctly you must have all your posts appearing on the same domain (e.g. myname.blogger.com) and be the only person using that domain. Including the JavaScript file and div tag in your Blogger template causes a nice AJAX category menu to be drawn into each of your blog pages.
Update If you want the names of the assigned categories to be displayed on each post instead of a transparent pixel, then use the following img tag: <img src="http://da.vidnicholson.com/blogtags.php?tag=Category Name&r=127&g=34&b=255&font=3" /> where r, g and b are decimal numbers between 0 and 255 specifying the amount of red, green and blue to use in the text colour and font is a number between 1 and 8 to specify the typeface that should be used.
Update I have added some true type fonts; font numbers 1, 2 and 3 are Times New Roman, Verdana and Arial respectively, 4 through to 8 are the older fixed width fonts.
Showing the number of posts in a category Change the Javascript shown above to <script language="JavaScript" src="http://da.vidnicholson.com/blogtags.php?dom=1&showcounts=1"> </script> if you would like the number of posts in each category to be shown on your blog.
Making a Backup If you would like your own copy of your category database as a backup just go to http://da.vidnicholson.com/blogtags.php?backup=yourdomain.com as often as you like and save the XML file that you are given. So, for example, to see my backup file go to http://da.vidnicholson.com/blogtags.php?backup=da.vidnicholson.com
All source code and related services that I release are "dontation-ware". If you use the above please
make a dontation (pay whatever you think the it is worth) or (where applicable) leave the link to my site attached.
Labels: Programming