bjs Posted April 27, 2004 Share Posted April 27, 2004 Hi, Can anyone recommend a simple php breadcrumb script? I'm looking for something that uses my directory structure, and would look something like this: Home > About > Contact Us I tried the one here: http://www.zend.com/zend/spotlight/breadcrumb28.php .. but couldn't get it to go more than one level deep. Anyway, I was just wondering if anyone has had any luck with this script or others. Quote Link to comment Share on other sites More sharing options...
!!blue Posted April 27, 2004 Share Posted April 27, 2004 I found these JavaScript breadcrumbs to be useful: http://webmediaconception.com/de/developme...dcrumbs.en.html They were easy to customize and all u do is add the JS file wherever u want the breadcrumbs to show up like so: <script language="JavaScript" type="text/javascript" src="js_paths.js"></script> Where js_paths.js is the name of the JavaScript file. hope that helps or at least gives u options... later, !!blue Quote Link to comment Share on other sites More sharing options...
bjs Posted April 27, 2004 Author Share Posted April 27, 2004 Thanks Blue, I'll check that out. Quote Link to comment Share on other sites More sharing options...
unibrain Posted April 27, 2004 Share Posted April 27, 2004 I use the script from http://www.baskettcase.com/classes/breadcrumb/ You can see an example at /www.unibrain.org It has lots of configuration options and was easy to setup. Quote Link to comment Share on other sites More sharing options...
deanavail Posted February 17, 2006 Share Posted February 17, 2006 Could someone comment on best practices for adding breadcrumb to a LAMP site, specifically: is it better to do it with a function or a class? with TCH now running PHP 4.4.1, is javascript even necessary to add breadcrumbs to a site? Is it necessary to write directory tree (folders and file structure) to a mysql table to improve depth and functionality? Zend has 2 breadcrumb navigation scripts listed below: newer: 0 A Cool Recursive Links Script- path.php http://www.zend.com/codex.php?id=362&single=1 is a 4 star older: Breadcrumbs navigation http://www.zend.com/codex.php?id=414&single=1 is a 0 star Any comments on these or suggestions to any best practices breadcrumb script? Quote Link to comment Share on other sites More sharing options...
deanavail Posted February 18, 2006 Share Posted February 18, 2006 I would like to hear about best practices in adding breadcrumb feature to a LAMP site. Maybe we can refine choices to the best out there. Here is a pure PHP script I am using to add breadcrumb navigation. I call this php script with an include on any page which needs to show breadcrumb as such: <p><? include('/breadcrumbgen.php'); ?> // breadcrumbden.php<? /* PHP dynamic link bar script by FranÁois Richardson. Free for use and abuse. Makes a series of links to the web root (printed as "Home"), each folder in the file path, and the filename. Underscores in the file names and folder names are shown as spaces to the visitor, and the file name is displayed without the extension. You can set the default web page name not to be displayed by assigning a value to the $def variable. I set this to "index" by default. Making it pretty with CSS: Each link has a class="dynNav" attribute, in case you need to apply special formatting with CSS. If you create a .dynNav class, the formatting will override that of any A{....} tag redefinition you do. The padded slash following each link also has the dynNav class applied to it, with <span> tags. If you need to apply different formatting to the links and the slashes, create your style for the slashes as .dynNav, then override it for the links with an a.dynNav selector. */ $def = "index"; //default web page for directories on your server. $dPath = $PHP_SELF; //Get the script path, relative to web root. $dChunks = explode("/", $dPath); //Separate out folder and file names by looking for slashes. ?> <a class="dynNav" href="/">Home</a><span class="dynNav"> >> </span> <!-- make a leading "home" link --> <? for($i=1; $i<count($dChunks); $i++){ //PHP arrays are 0 inxeded but we are skipping the first element because of the way explode() works. echo("<a class=\"dynNav\" href=\"/"); //Make each chunk a link. for($j=1; $j<=$i; $j++){ //Subloop to create the path for each chunk. echo($dChunks[$j]); //Write each piece of the chunk's path. if($j!=count($dChunks)-1) echo("/");//If that piece was a folder name, append a slash. } if($i==count($dChunks)-1) { //If the chunk is a file, not folder name... $prChunks = explode(".", $dChunks[$i]); //take out the file extension... if ($prChunks[0] == $def) $prChunks[0] = ""; //don't display the filename if it's index or whatever default you specified. $prChunks[0] = $prChunks[0] . "</a>"; //add the closing tag. } else $prChunks[0]=$dChunks[$i] . "</a><span class=\"dynNav\"> / </span>"; //Otherwise, just use the chunk name, close the a tag and add a paddeslash for display. echo('\"\>'); echo(str_replace("_" , " " , $prChunks[0])); //Finish writing the link, replacing underscores with spaces for the end user. } ?> Quote Link to comment Share on other sites More sharing options...
deanavail Posted February 28, 2006 Share Posted February 28, 2006 Hello if you are out there TCH members, moderators, and Gurus, I have revised the above script further should any one care to discuss breadcrumb scripts. Quote Link to comment Share on other sites More sharing options...
carbonize Posted February 28, 2006 Share Posted February 28, 2006 Shouldn't $dPath = $PHP_SELF; //Get the script path, relative to web root. be $dPath = $_SERVER['PHP_SELF']; //Get the script path, relative to web root. ?? Quote Link to comment Share on other sites More sharing options...
weissi Posted March 5, 2006 Share Posted March 5, 2006 (edited) i like this one. you'll find it at: http://www.drweb.de/php/brotkrumen.shtml ><?php $an="you are here: "; $home="http://www.drweb.de/"; // your domain $pie=explode("/","$_SERVER[PHP_SELF]"); $tr=" > "; // Alternate: ':', '/' $b=count($pie); echo $an."<a href=\"".$home."\">Startseite</a>"; // Alternate: 'Home', 'Start' for($a=1;$a<$b-1;$a++){ $ta=$ta.$pie[$a]."/"; echo $tr."<a href=\"".$home.$ta."\">".ucfirst($pie[$a])."</a>";} $file=explode('.',ucfirst($pie[$b-1])); echo "<b>".$tr.$file[0]."</b>"; ?> Edited March 5, 2006 by weissi Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 5, 2006 Share Posted March 5, 2006 Welcome to the forums weissi Thanks for the code snippet Quote Link to comment Share on other sites More sharing options...
TCH-Thomas Posted March 5, 2006 Share Posted March 5, 2006 Welcome to the forum, weissi. Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 5, 2006 Share Posted March 5, 2006 Is there a way to put these breadcrumbs into your site using includes? ie, I dont Imagine that I could put it in the include that is right under my logo. I would imagine that it would make the breadcrumb the same for everypage (home/includes/crumb.php). Is that right? Quote Link to comment Share on other sites More sharing options...
deanavail Posted March 7, 2006 Share Posted March 7, 2006 So we have dialogue, Thank you all for stopping by. I was beginning to think that script talk was dead at TCH Shouldn't $dPath = $PHP_SELF; be $dPath = $_SERVER['PHP_SELF']; ?? carbonize,$PHP_SELF = $_SERVER['DOCUMENT_ROOT'] if register_globals is set to on, u can check your setting at www.yoursite.com:2082/phpinfo.php weissi, I like how cpmpact your code is, 12 lines versus 22 lines in my improved FBD script, shown below. Both scripts are identical in how they strip out "/" from URI Path and the file extensions ".php" etc. using two explode() functions. The FBD script however offers the following advantages for those additional 10 lines of code, namely: The ability to turn the current file into a link and not just the heirechal structure in the breadcrumb. The ability to hide certain filenames within folders from the breacrumb by defining those in $def variable. The ability to turn underscores in file names to spaces in the breadcrumb. The ability to use CSS to style both links and link separator in the breadcrumb using class .dynNav ><? /* PHP dynamic link bar script FranÁois/Brett/Deano, AKA FBD, script set root with $def variable set Home link with $rootlink variable set separator with $separator variable set link style with CSS class a.dynNav set separator style with CSS class .dynNav */ $rootlink = "Home"; // define root link $separator = ">>"; // define separator $def = "index"; //default web page for directories on your server. $dPath = $PHP_SELF; //Get the script path, relative to web root. $dChunks = explode("/", $dPath); //Separate out folder and file names by looking for slashes. $dChunkcount = count($dChunks); ?> <a class="dynNav" href="/"><? print $rootlink ?></a> <span class="dynNav"><? print $separator ?> </span> <!-- make a leading $rootlink --> <? for($i=1; $i<$dChunkcount; $i++) { //PHP arrays are 0 inxeded skipping the first element because of how explode() works echo("<a class=\"dynNav\" href=\"/"); //Make each chunk a link. for($j=1; $j<=$i; $j++) { //Subloop to create the path for each chunk. echo($dChunks[$j]); //Write each piece of the chunk's path. if($j!=$dChunkcount-1) print "/"; //If that piece was a folder name, append a slash. } if($i==$dChunkcount-1) { //If the chunk is a file, not folder name... $prChunks = explode(".", $dChunks[$i]); //take out the file extension... if ($prChunks[0] == $def) $prChunks[0] = ""; //don't display the filename if it's index or whatever default you specified. $prChunks[0] = $prChunks[0] . "</a>"; //add the closing tag. } else $prChunks[0]=$dChunks[$i] ."</a><span class=\"dynNav\"> ". $separator." </span>"; //Otherwise, just use the chunk name, close tag and add a paddeslash for display. echo "\">"; echo(str_replace("_" , " " , $prChunks[0])); //Finish writing the link, replacing underscores with spaces for the end user } ?> wampthing, you absolutely can place your breadcrumb script in an includes folder , say /home/includes/crumb.php and call it up on any page by simply adding the following command: ><?php include $_SERVER['DOCUMENT_ROOT']."/includes/crumb.php"; ?> Quote Link to comment Share on other sites More sharing options...
deanavail Posted March 7, 2006 Share Posted March 7, 2006 That should say $PHP_SELF = $_SERVER['PHP_SELF'] Quote Link to comment Share on other sites More sharing options...
carbonize Posted March 7, 2006 Share Posted March 7, 2006 (edited) carbonize,$PHP_SELF = $_SERVER['DOCUMENT_ROOT'] if register_globals is set to on, u can check your setting at www.yoursite.com:2082/phpinfo.php Yes but my point is you should never assume. It is always best to code for global variables being switched off even more so as that is now the default. I doubt any TC server has globals switched on nor would any other host who has half a clue leave them switched on. Edited March 7, 2006 by carbonize Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 7, 2006 Share Posted March 7, 2006 So I just installed the script, and am in fact having it show only the location of the included file. I wonder if it is because my site is done with .shtml with .htm files embeded in it instead of html with php. Any ideas anyone. (thanks btw for your response deanavail) Quote Link to comment Share on other sites More sharing options...
deanavail Posted March 7, 2006 Share Posted March 7, 2006 carbonize, you are absolutely right, never never assume. wampthing, it should work fine, can you recheck that you copied script verbatim and save it as crumb.php in your www.sitedomain.com/includes/crumb.php edit a new page and place <?php include $_SERVER['DOCUMENT_ROOT']."/includes/crumb.php"; ?> at the top add <? echo "testing 123" ;?> right below it save page as test.php right below root and upload browse this test page www.sitedomain.com/test.php and what do u see? although I have not tested php code in .shtml, you have to tell php to parse within .shtml files. This is likely done in your php.ini file, check with TCH support. good luck Quote Link to comment Share on other sites More sharing options...
carbonize Posted March 8, 2006 Share Posted March 8, 2006 You tell the server to send shtml files to PHP via the .htaccess file. php.ini is just where PHP keeps it's settings. It would be in Apaches config file where you would specify what files are treated as what and the .htaccess can be used to override this. Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 8, 2006 Share Posted March 8, 2006 I tried adding .shtml to the following >XBitHack on AddType application/x-httpd-php .htm .html It messed up the pages. It forced them to be saved to your hard drive. I had a similar problem before and came away with the understanding that .shtml wasnt a very good format to be including php files. Perhaps I am missing something. Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted March 8, 2006 Share Posted March 8, 2006 If you add .shtml to AddType application/x-httpd-php .htm .html as in AddType application/x-httpd-php .htm .html .shtml you can include php in .shtml and you do not need the XBitHack on but you give up the other includes like <!--#include virtual="/footer.html" --> Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 8, 2006 Share Posted March 8, 2006 I haven't used .shtml pages since coming to TCH. Yes, my old host required .shtml extensions to use #include statements. Once I moved the accounts here I switched them all back to .htm and .html and have even changed one site to .php. It's a task if you have a lot of pages but in the long run well worth it. Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 8, 2006 Share Posted March 8, 2006 but you give up the other includeslike <!--#include virtual="/footer.html" --> Maybe that is my problem. I am using the <!--#include virtual="/footer.html" --> include. It sounds like I would need to change all of the previous includes to one of the following; <?php include $_SERVER['DOCUMENT_ROOT'].""; ?> <?php include(); ?> Is that right. Perhaps that is what is causing my errors when I have .shtml included in my htaccess file. AddType application/x-httpd-php .htm .html .shtml Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted March 8, 2006 Share Posted March 8, 2006 Yes that is the reason the other includes do not work now. I prefer <?php include $_SERVER['DOCUMENT_ROOT']."/header.php"; ?> With the php includes you can use other tricks like a different title on each page. the top of a page starts like this <?php // add header and additional title $page_title="home"; include $_SERVER['DOCUMENT_ROOT']."/header.php"; // begin main content ?> then in header.php the title is dispayed as My Web Site - <?php print("$page_title"); ?> Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 8, 2006 Share Posted March 8, 2006 Cool Beans, Ill look into changing the includes as a quick fix, then when I have time, Ill get my site moved away from shtml so that I can play with the big boys. Thanks all Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 9, 2006 Share Posted March 9, 2006 I went and changed the links as mentioned. The site still gave me errors, so I just went and changed it so that I was including PHP files in the html. I am done with .shtml (on that site anyway) And to get back to the point of this thread, the breadcrumb scripts is working dandy. Quote Link to comment Share on other sites More sharing options...
carbonize Posted March 9, 2006 Share Posted March 9, 2006 Well if you are worried about people not being able to find your pages after you change them to .php you could always use your .htaccess to send them to the correct page. Or better yet write a smart 404 page using PHP to explain the reason for the changes and give them a link to the correct url for the page they requested. Quote Link to comment Share on other sites More sharing options...
deanavail Posted March 9, 2006 Share Posted March 9, 2006 glad to hear you got the breadcrumb script working. Hope to see you all very soon on another script discussion. Quote Link to comment Share on other sites More sharing options...
wampthing Posted March 9, 2006 Share Posted March 9, 2006 Well if you are worried about people not being able to find your pages after you change them to .php you could always use your .htaccess to send them to the correct page. Or better yet write a smart 404 page using PHP to explain the reason for the changes and give them a link to the correct url for the page they requested. I know how to redirect specific files, and anything in a specific folder. I dont know how to redirect an extension of .shtml to the same url, but endind with php. Id like to do it via htaccess for time sake. Any Ideas? Quote Link to comment Share on other sites More sharing options...
carbonize Posted March 9, 2006 Share Posted March 9, 2006 Off the top of my head no but it would be a case of using regex. If nobody has answered by the time I get home I'll throw something together. The smart 404 page is the better option though as it informs the user of the change incase they have bookmarked the page. Quote Link to comment 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.