foreach ($this->myUrl as $value) { $breadcrumbs[] = $value === $this->anchorText ? '<li> / <a href="/' . implode('/', $this->myUrl) . '">' . $value . '</a></li>' : '<li> / ' . $value . '</li>'; } $breadcrumbs[] = '</ol>'; $this->breadcrumbs = implode('', $breadcrumbs); } public function getBreadcrumbs() { return $this->breadcrumbs; } } class Webpage extends Template { public $anchorText; public $myUrl; public function __construct() { $this->myUrl = explode('/', ltrim($_SERVER['REQUEST_URI'], '/')); if (strlen(trim($this->myUrl[count($this->myUrl) - 1])) === 0) { $this->anchorText = $this->myUrl[count($this->myUrl) - 2]; unset($this->myUrl[count($this->myUrl) - 1]); } else { $this->anchorText = $this->myUrl[count($this->myUrl) - 1]; } $this->getBreadcrumbNavigation(); } } print_r('<pre>'); $webpage = new Webpage(); echo $webpage->getBreadcrumbs(); exit;