*Added functionality to capitalize trail items & remove underscores & hyphens:
<?php
// breadcrumb trail created by Jon Ruttan, based on breadcrumb menu by Chris Poole(chrispoole.com)
function breadcrumb() {
$url = $_SERVER[“REQUEST_URI”];
$urlArray = array_slice(explode(“/”,$url), 0, -1);
// Set $dir to the first value
$dir = array_shift($urlArray);
echo ‘Home‘;
foreach($urlArray as $text) {
$dir .= “/$text”;
echo ‘ > ‘ . str_replace(“-“, ” “, ucwords(str_replace(‘_’, ‘ ‘, $text))) . ‘‘;
}
}
?>
Silly me, I missed adding a space on this line:
echo ' > <a href="'.$dir.'">' . str_replace("-", " ", ucwords(strtr($text, array('_' => ' ', '-' => ' ')))) . '</a>';
Wow, thanks, this is great. I’m not sure it does 100% of what I was hoping for, but it’s going to work until we run into the issues I fear. 🙂
thanks for the contribution.
Thanks, ancawonka. I appreciate your feedback.
I condensed the following line further after noticing the extraneous code in my previous post:
echo ' > <a href="'.$dir.'">' . ucwords(strtr($text, array('_' => ' ', '-' => ' '))) . '</a>';
What sort of issues do you foresee?
Thanks for the code. I put it in the functions.
// breadcrumb trail created by Jon Ruttan, based on breadcrumb menu by Chris Poole(chrispoole.com)
function the_breadcrumb() {
$url = $_SERVER["REQUEST_URI"];
$urlArray = array_slice(explode("/",$url), 0, -1);
// Set $dir to the first value
$dir = array_shift($urlArray);
echo '<a href="/">Home</a>';
foreach($urlArray as $text) {
$dir .= "/$text";
echo ' > <a href="'.$dir.'">' . ucwords(strtr($text, array('_' => ' ', '-' => ' '))) . '</a>';
}
}
And in theme
<?php the_breadcrumb(); ?>
Works great!!!
Thanks.
Seems like a very sensible spot for it, JimmyJack. 😉
Here’s the latest, reworked version:
<?php
// created by Jon Ruttan. Based on breadcrumb menu by Chris Poole(chrispoole.com)
function breadcrumb() {
$url = $_SERVER['REQUEST_URI'];
$urlArray = explode('/', rtrim($url, '/'));
// Set $dir to the first value
$dir = array_shift($urlArray);
$breadcrumb = '<a href="/">Home</a>';
foreach($urlArray as $text) {
$dir .= "/$text";
$breadcrumb .= ' > <a href="'.$dir.'">' . ucwords(strtr($text, '_-', ' ')) . '</a>';
}
return $breadcrumb;
}
?>