Forum Moderators: coopster

Message Too Old, No Replies

Breadcrumbs not creating all links?

         

mr_nabo

12:53 pm on Apr 4, 2010 (gmt 0)

10+ Year Member



Hi,

Can anyone see what's going wrong here please? I'm running some PHP breadcrumbs code I wrote below, but When I visit a URL like:

www.example.com/photos/other/

The breadcrumbs is only generating this:

<p id="crumbs"><span class="bold">You are here:</span> <a title="Home Page" href="/">Home</a> &gt; <a href="/photos/">Photos</a> &gt; <a href="/other/">Other</a></p>


But I wanted this:

<p id="crumbs"><span class="bold">You are here:</span> <a title="Home Page" href="/">Home</a> &gt; <a href="/photos/">Photos</a> &gt; <a href="/photos/other/">Other</a></p>


Anyone have any idea why my 'Other' link isn't displaying the path '/photos/other/'?

My PHP code is:

<?php
// CREATE BREADCRUMBS

// Get current url and process it:
$current = $_SERVER['REQUEST_URI'];
// Replace underscores and dashes with spaces
$current = str_replace("_", " ", $current);
$current = str_replace("-", " ", $current);
// Create array with parts as separated by a slash
$currentArray = explode("/",$current);

$breadCrumbHTML = '<a href="/" title="Home Page">Home</a>';
// Loop through the array and print out the results
for( $i=1; $i < count($currentArray) -1; $i++) {
// capitalize the first letter of each word in the section name
$crumbName = ucwords($currentArray[$i]);
// rebuild the navigation path
$newTrail = $currentArray[$i] . '/';
// build the HTML for the breadcrumb trail
$breadCrumbHTML .= ' &gt; <a href="' . $newTrail . '">' . $crumbName . '</a>';
}
?>
<p id="crumbs"><span class="bold">You are here:</span> <?php echo $breadCrumbHTML; ?></p>


Thanks

[edited by: tedster at 3:16 pm (utc) on Apr 4, 2010]
[edit reason] switch to example.com - it can never be owned [/edit]

Readie

12:59 pm on Apr 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$newTrail = $currentArray[$i] . '/';

Over writing the $newTrail on each loop, needs to be appending to it.

$newTrail .= $currentArray[$i] . '/';

Should work

mr_nabo

1:01 pm on Apr 4, 2010 (gmt 0)

10+ Year Member



Readie, you are a dude.

Sometimes it's the most simplest things.