SharkBait Posted June 26, 2006 Share Posted June 26, 2006 How does one do the breadcrumbs in php?Do I use a session to keep track of where they are?Kind like phpfreaks: PHP Help Forums > PHP and MySQL > PHP Help Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/ Share on other sites More sharing options...
Leovenous Posted June 27, 2006 Share Posted June 27, 2006 I've been wondering this myself, and yeah, sessions were the first thing that popped into my mind. Maybe you could make a breadcrum variable that is the link, then add or subtract from it. I dunno. Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49890 Share on other sites More sharing options...
dptr1988 Posted June 27, 2006 Share Posted June 27, 2006 The $_SERVER['PHP_SELF'] variable gives you your url location. Can't you use that to keep track of where the user is? Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49891 Share on other sites More sharing options...
Leovenous Posted June 27, 2006 Share Posted June 27, 2006 Its not so much where the user is, but where the user came from. For instance, in the breadcrumb for this forum, how does the "PHP Help" link know to be there, and for that matter, the links ahead of it? Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49892 Share on other sites More sharing options...
AndyB Posted June 27, 2006 Share Posted June 27, 2006 [a href=\"http://www.zend.com/zend/spotlight/breadcrumb28.php\" target=\"_blank\"]http://www.zend.com/zend/spotlight/breadcrumb28.php[/a][a href=\"http://www.baskettcase.com/classes/breadcrumb/\" target=\"_blank\"]http://www.baskettcase.com/classes/breadcrumb/[/a]have fun Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49893 Share on other sites More sharing options...
.josh Posted June 27, 2006 Share Posted June 27, 2006 breadcrumb examples i've seen use your dir structure. so like, if you store your files in the a dir structure in the same way you want the breadcrumbs to show, you can base your breadcrumb off that Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49894 Share on other sites More sharing options...
AndyB Posted June 27, 2006 Share Posted June 27, 2006 [a href=\"http://www.sillybean.net/archives/452\" target=\"_blank\"]http://www.sillybean.net/archives/452[/a] as a follow-up to Crayon Violent's suggestion Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-49895 Share on other sites More sharing options...
SharkBait Posted June 27, 2006 Author Share Posted June 27, 2006 Ah thanx for the replies. I guess I'll have to do a combination of it.directory and file ;) I'll play around and see what I can come up with with help of the examples you guys have posted. Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-50106 Share on other sites More sharing options...
SharkBait Posted June 27, 2006 Author Share Posted June 27, 2006 [!--quoteo(post=388522:date=Jun 27 2006, 07:45 AM:name=SharkBait)--][div class=\'quotetop\']QUOTE(SharkBait @ Jun 27 2006, 07:45 AM) [snapback]388522[/snapback][/div][div class=\'quotemain\'][!--quotec--]Ah thanx for the replies. I guess I'll have to do a combination of it.directory and file ;) I'll play around and see what I can come up with with help of the examples you guys have posted.[/quote]This is what I came up with:(how I wish php tags were working ;))[code]<ul id="breadcrumbs"><?php// Get Directory Path and Scriptname to create BreadCrumbs$parts = explode("/", dirname($_SERVER['PHP_SELF']));echo "<li><a href=\"/\"Home</a> ";foreach($parts as $key => $dir) { $label = ucwords($dir); $url = ""; for($i = 1; $i <= $key; $i++) { $url .= $parts[$i]."/"; } if($dir != "") { echo "<li>> a href=\"/{$url}\">{$label}</a></li> "; }}$script = explode(".", basename($_SERVER['PHP_SELF']));if(script != "") { echo "<li>> ". ucwords($script[0])."</li>";}?></ul>[/code]Thanx to the sillybean.net example and suggestions :) My Breadcrumbs look like:Home > Admin > ScriptName Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-50116 Share on other sites More sharing options...
matt_vo Posted November 14, 2006 Share Posted November 14, 2006 Hi all,I'm also using the Sillybean example. It's quite easy to use but I still have a question. What if I need to remove, or not display, the two first directories. For example, I would like to remove Home and Dir1 from:Home > Dir1 > Dir2 > Dir3 > HereRemoving Home is easy, just commenting out, but how about Dir1? If I use unset ($parts[1]), it removes Dir1 from the breadcrumb but then the links are wrong.ThanksMatt Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-124448 Share on other sites More sharing options...
.josh Posted November 14, 2006 Share Posted November 14, 2006 it's hard to determine how to fix that without you showing your code, but if it's because of some kind of loop you are doing that is dependant on the array keys being 12345 instead of 1245 then you can use [url=http://www.php.net/array_values]array_values()[/url] to reset the keys after you have unset one of them. consider this example:[code]<?php // example array $blah = array('a','b','c','d','e'); // display what the key - value initially looks like // will show keys 0,1,2,3,4 foreach ($blah as $key => $val) { echo "$key - $val <br>"; } // unset the middle element unset ($blah[2]); // show what the key-val looks like now // shows 0,1,3,4 foreach ($blah as $key => $val) { echo "$key - $val <br>"; } // reset the keys $blah = array_values($blah); // display results from reseting the keys // shows 0,1,2,3 foreach ($blah as $key => $val) { echo "$key - $val <br>"; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12947-bread-crumbshowto/#findComment-124556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.