• For those wishing to use a non-plugin based breadcrumb trail, simply insert the following code in your template:

    <?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 '<a href="/">Home</a>';
    	foreach($urlArray as $text) {
    		$dir .= "/$text";
    		echo ' &raquo; <a href="'.$dir.'">' . str_replace("-", " ", $text) . '</a>';
    	}
    }
    breadcrumb();
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Barret Ruttan

    (@capn-code)

    *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))) . ‘‘;
    }
    }
    ?>

    Thread Starter Barret Ruttan

    (@capn-code)

    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.

    Thread Starter Barret Ruttan

    (@capn-code)

    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.

    Thread Starter Barret Ruttan

    (@capn-code)

    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;
    }
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Breadcrumb trail’ is closed to new replies.