I’m trying to create a breadcrumb which pulls the data from the link and separates out and stylizes. So far I have the following:
[php]<?php
/**
*
- @Create Breadcrumbs Trail.
- @copyright Copyright © 2008 PHPRO.ORG. All rights reserved.
- @version //autogentag//
- @license new bsd http://www.opensource.org/licenses/bsd-license.php
- @filesource
- @package Breadcrumbs
- @Author Kevin Waterson
*/
class breadcrumbs{
/*
* @string $breadcrumbs
*/
public $breadcrumbs;
/*
* @string $pointer
*/
private $pointer = '»';
/*
* @string $url
*/
private $url;
/*
* @array $parts
*/
private $parts;
/*
* @constructor - duh
*
* @access public
*
*/
public function __construct()
{
$this->setParts();
$this->setURL();
$this->breadcrumbs = '<a href="'.$this->url.'">Home</a>';
}
/*
*
* @set the base url
*
* @access private
*
*/
private function setURL()
{
$protocol = $_SERVER["SERVER_PROTOCOL"]=='HTTP/1.1' ? 'http' : 'https';
$this->url = $protocol.'://'.$_SERVER['HTTP_HOST'];
}
/*
* @set the pointer
*
* @access public
*
* @param string $pointer
*
*/
public function setPointer($pointer)
{
$this->pointer = $pointer;
}
/**
*
* @set the path array
*
* @access private
*
* @return array
*
*/
private function setParts()
{
$parts = explode('/', $_SERVER['REQUEST_URI']);
array_pop($parts);
array_shift($parts);
$this->parts = $parts;
}
/**
*
* @create the breadcrumbs
*
* @access public
*
*/
public function crumbs()
{
foreach($this->parts as $part)
{
$this->url .= "/$part";
$this->breadcrumbs .= " $this->pointer ".'<a href="'.$this->url.'">'.$part.'</a>';
}
}
} /*** end of class ***/
?>
<?php /*** a new breadcrumbs object ***/ $bc = new breadcrumbs; /*** set the pointer if you like ***/ $bc->setPointer('•'); /*** create the trail ***/ $bc->crumbs(); /*** output ***/ echo $bc->breadcrumbs; ?>[/php]The output appears as
Home • then next page • exctetra.
The odd part is that when you get to a page within our directory which has spaces in the title, the breadcrumb appears as
Home • directory • ##### • business-name - # represents the post number
We would love to have this show as
Home • Directory • Business Name
how would we be able to styleize this so we have capitols on the first letter and no dashes? Additionally if you can figure out the number line, that would be awesome too, but not a priority.