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 SEO. 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 SEO 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 PHP script, or you can see the complete breadcrumb script with notes included.
<?phpfunction 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>";
Technorati





