breadcrumbs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

breadcrumbs

Post by ericsodt »

I have looked on the site and could not find anything to do with Breadcrumbs... can someone PLEASE help me out. I am looking for a way to create them and display something like:

main > page1 > page2 > etc... etc...

How do I find the file paths I have seen people us $PHP_SELF, but that did not work for me... any clues would be greatly appreciated

Thanks
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Well, there are numerous of ways. You could use something similiar to:

Code: Select all

$bread = $_SERVER["SCRIPT_FILENAME"];
$crumbs = explode('/',$bread);
print_r($crumbs);
Just change it to fit your prefered solution...
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

just wondering, why are they called "Breadcrumbs"?

Mark
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Leaves a trail... Kinda like a "You are here" mark.

This forum has an excellent example:
The PHP Forums Forum Index -> PHP - Normal -> etc.

Using it with a path, exploding the / make s a good start for such.
/www/coding/php/security/sessions
/www/coding/asp/snippets/
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Bech100 wrote:just wondering, why are they called "Breadcrumbs"?
It's a path to follow back to where you came from - as used in fairy tales such as Hansel and Gretel.
Grimms' Fairy Tales wrote:Just wait, Gretel, until the moon rises, and then we shall see the crumbs of bread which I have strewn about, they will show us our way home again.
Mac
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Post by ericsodt »

Jam,

This works for the first page but does not continue onto the other pages

"Array ( [0] => " is what I get on all my pages... Somehow the path is not getting into the array

Such as when I go from page1.php to page2.php, the array does not grow... any help would greatly be appreciated
JAM wrote:Well, there are numerous of ways. You could use something similiar to:

Code: Select all

$bread = $_SERVER["SCRIPT_FILENAME"];
$crumbs = explode('/',$bread);
print_r($crumbs);
Just change it to fit your prefered solution...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What do your page paths look like? There is no one-size fits all solution for breadcrumb trails. You may find that your link structure neccessitates the use of sessions to keep track of users activity.

Mac
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

in a forums setting, you can do that via the get string with relative ease... but... not sure about how to do it in your setting since i don't really know how the struture of the site is
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I can only show you examples, and let you work from there:

Code: Select all

<?php
// a slice of my bread
    $bread = '/couriers/gods/jam/www/code/example.php';
// make crumbs, removing the first char (workaround for empty array 0)
    $crumbs = explode('/',substr($bread,1)); 
// remove the filename
    $removed = array_pop($crumbs);
// print the crumbs, then the page...
    print_r($crumbs); 
    echo $removed;
?>

Returns: 
Array
(
    [0] => couriers
    [1] => gods
    [2] => jam
    [3] => www
    [4] => code
)
example.php
Post Reply