O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #4. Build a Breadcrumb Trail

Use a breadcrumb trail to tell your users where they are on your site.

A breadcrumb trail is a list of links at the top of a page that indicates where a person is in the site's organizational hierarchy.

Tip

A breadcrumb trail is not, as the term might suggest, the set of pages that a person navigated through to get to his destination. The user already has the Back button for retracing his steps.

A breadcrumb trail allows a user to navigate back up the hierarchy a little to where he would find more relevant information. For example, the trail might be: Home | Platforms | Portables | PSP. The user could easily navigate back to the Portables page, which lists all of the portable game consoles, the Platforms page, which lists the different gaming platforms, or the home page, all with a single click.

Figure 2-3 shows the breadcrumb trail that Yahoo! uses in its directory to show where you are. In this case, I'm in the Buddy section of the Comedy category, within the Titles area of Movies and Films. As a user, I can go back to any level of organization that suits my interests.

The Yahoo! directory breadcrumb trail

Figure 2-3. The Yahoo! directory breadcrumb trail

By convention, the last item on the list is the current page and is not given a link. The first item on the list is the home page of the site.

The Code

To add breadcrumbs to your own site, save the code shown in Example 2-4 as showpage.php ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required