Breadcrumbs with PHP

Technorati Technorati Tags:

RSS Subscription
Posted In:
Jan 17th, 2009 @ 8:23 pm PST
(0) Comments

During the development of this site there came a time—as there should in all well designed sites that care about usability and SEO—to consider a script that would execute a breadcrumb trail. I looked over some scripts during a search of what other developers before me had used to get the job done, and I came across a few that I'm sure would have worked quite well. Yet, I never feel comfortable using a piece of software unless I know exactly what it does, so I turned to PHP in an attempt to get a better understanding of how to add this indispensable navigational tool.

The primary goals of my script was to accomplish usability and . The user should be able to determine his/her position within the hierarchy while revealing the sites structure to the search engines. Breadcrumbs are useful to for many reasons.

  • Keyword-rich anchor text
  • Every page links to the Home page
  • Allows indexing of more pages
  • Lightweight navigation system for mobile devices

Here is some of my script, or you can see the complete breadcrumb script with notes included.

<?php
function breadCrumbs($url, $crumbDivider = "»", $wordDivider = "-", $id = "breadCrumbs")
{
    $dirs = explode("/", $url);
    $page = ucwords(implode(" ", 
            explode($wordDivider, 
            substr($dirs[sizeof($dirs) - 1], 0, 
            strpos($dirs[sizeof($dirs) - 1], ".")))));
    if(sizeof($dirs) > 2)
    {
       $path = array("Home");
       $href = "http://{$_SERVER['HTTP_HOST']}/";
       $breadCrumbs = "<div id='{$id}'><a href='{$href}'>Morgan</a>";
Share this Post

There are 0 comments for this post.

Add a comment to this post!

(Thanks!)

HTML Allowed (but not necessary): <p>, <a href=' '>*, <em>, <pre>, <code> & <blockquote>.  *rel='nofollow' is set for all <a> tags.