Main Page Content
Breadcrumbs For All
Several sites now have a breadcrumb trail as a navigation aid. The appeal is obvious: help the user work out where they are in a hierarchical site. It's pretty good usability, which is probably why Jakob Nielsen has one on his site. Here's how to add one to your own (Unix/Apache/Perl-hosted) site. This code works for simple hierarchical sites - ones where there is a simple tree structure. Below the home page, there are a set of folders, each of which can have layers of subfolders. Each folder can contain pages. In other words, your basic site. The reason for this is that this is not a re-creation of the user's browser history; it's a visualisation of a top-to-bottom path through your information architecture. The way it works is extremely simple:
and the (URL-encoded) query string sets the title;The title can also have links in it as long as you escape all the HTML entities - useful if you want to have a sub-article without creating a subdirectory:
(you delete the class attribute and value).
- Take a simple URL like
http://foo.co.uk/articles/content/systems.html
; - Swap
http://foo.co.uk
for Home as it's the home page of the site; - Swap
systems.html
for a sensible title (a truely gifted piece of code would pick this up from the page title with no performance loss. This is no such piece of code, sorry, it picks it up from a query string); - Split the rest of the URL at the slashes;
- Add a link to all but the current page title;
- Stick the bits together in order, using a sensible separator such as ->;
- Output it all as a single string to the page.
use locale;
Also note:You call the script by means of an SSI call:<!--#include virtual="/cgi-bin/cookie_trail.cgi?title=You%20put%20your%20title%20here" -->
and the (URL-encoded) query string sets the title;The title can also have links in it as long as you escape all the HTML entities - useful if you want to have a sub-article without creating a subdirectory:
?title=<a href="library.html"%20class="crumb">Building%20a%20library</a>%20->%20Current%20Reading%20List
My site has a special CSS class for the breadcrumb trail, so all the links output by the script will have class="crumb"
in them. If you want them out, then this is the line to edit:$html .= qq -> <a href="$crumbs_path[$i]/" class="crumb">$crumbs[$i]</a> ;
(you delete the class attribute and value).