Re: recommendations for good breacrumbs script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 3:35 PM -0500 3/11/06, Bruce Gilbert wrote:
Hello,

I am looking around for a good PHP breadcrumbs navigation script that
would out put a path based on file structure.  For instance if I had a
folder called Portfolio and within that folder I had a index.php file
and another file called Websites.php. When I was on the websites.php
page, the breadcrumbs path would display Home >> Portfolio >> Websites
and Home and Portfolio would be hyperlinks. I don't want the
breadcrumbs to display a .php extension. I could of course hard code
this, but would rather find an automated solution.

Thanks in advance for any assistance!



I wrote this script quite a while ago (in PHP3.0, if I recall correctly); it could probably stand to be cleaned up, but it works OK.

You can tell it the URL path you'd like referenced as the top level of the trail, the default separator (in your case, '>>'), any extra attributes you want in your A HREF tag, and what file names it should ignore. By default, it ignores anything starting with index - eg index.php, index.html. It also replaces underscores with spaces in the current directory/filename, and uppercases the resulting words. Of course, you could remove/alter that functionality if you want.

Hope that email client linewraps don't muck it up too badly...

	steve


<?php

function path_to_crumbtrail($TopLevel='', $Separator='&nbsp;|&nbsp;', $LinkAttr='', $IgnoreName='index') {

      $IgnoreNameRegEx  = $IgnoreName ? '/'.$IgnoreName.'[.]?[a-z]*$/i' : '';
      $CrumbBits        = array();
      $Crumbs           = '';
      $LinkAttrString   = '';
      $CurrPath         = $TopLevel;
$X = preg_replace('#^/#', '', preg_replace("'^$TopLevel'U", '', $_SERVER['SCRIPT_NAME']));
      $X                = preg_replace('#/$#', '', $X);

      if ($IgnoreNameRegEx) {
         $X = preg_replace($IgnoreNameRegEx, '', $X);
      }
$X = preg_replace('#/$#', '', $X);
      $PathBits   = preg_split("'/'", $X);

      if (is_array($LinkAttr)) {
         foreach ($LinkAttr as $Att=>$Val) {
            $LinkAttrString .= " $Att=".'"'.$Val.'"';
         }
      } elseif ($LinkAttr) {
         $LinkAttrString = ' '.trim($LinkAttr);
      }

      if (is_array($PathBits)) {

         $PathCount = count($PathBits);

         for ($i=0; $i<$PathCount; $i++) {

            $ThisLevel = trim($PathBits[$i]);

            if ($ThisLevel) {
               $CurrPath   .= "/$ThisLevel";
               $ThisLevel  = preg_replace('/\..*$/U', '', $ThisLevel);
$ThisLevel = preg_replace('/ /', '&nbsp;', ucwords(preg_replace('/_/', ' ', $ThisLevel)));

$CrumbBits[] = ($i == $PathCount-1 ? $ThisLevel : '<a href="'.$CurrPath.'"'.$LinkAttrString.'>'.$ThisLevel.'</a>');
            }
         }

         $Crumbs = implode($Separator, $CrumbBits);
      }

      return $Crumbs;
   }

?>

--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg                                http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center                            sbedberg@xxxxxxxxxxx |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux