Jump to content

Breadcrumb ...


jimbobsquarepants

Recommended Posts

I've only been playing with PHP for about 4 months so im slowly getting there.

On my test website i've made a breadcrumb trail ... for example it might look something like this

Home >> Customer Information >> Help >> FAQs.

Is it poss to do an if statement on the trail?

So if the breadcrumb trail says Help then do a song and dance  ;D

Cheers
Link to comment
https://forums.phpfreaks.com/topic/18632-breadcrumb/
Share on other sites

Think thats the bit you need

<?php
/*
  $Id: breadcrumb.php,v 1.3.2.5 2004/09/20 14:21:29 tds Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class breadcrumb {
    var $_trail;

    function breadcrumb() {
      $this->reset();
    }

    function reset() {
      $this->_trail = array();
    }

    function add($title, $link = '') {
      $this->_trail[] = array('title' => $title, 'link' => $link);
    }

    function trail($separator = ' - ') {
      $trail_string = '';

      for ($i=0, $n=sizeof($this->_trail); $i<$n; $i++) {
        if (isset($this->_trail[$i]['link']) && tep_not_null($this->_trail[$i]['link'])) {
          $trail_string .= '<a href="' . $this->_trail[$i]['link'] . '" class="headerNavigation">' . $this->_trail[$i]['title'] . '</a>';
        } else {
          $trail_string .= $this->_trail[$i]['title'];
        }

        if (($i+1) < $n) $trail_string .= $separator;
      }

      return $trail_string;
    }

    function custom_file($webdir, $base) {
      // Note: needs to be global. Needs not to be initialised to anything.
      global $badgermushroom; // apols for silly variable name, needs to be
      // unique.
      global $STICKY_CUSTOM_FILES;
      tep_session_register("badgermushroom");
      if (!$badgermushroom) { $badgermushroom = array(); }

      $append = "";
      for($i=0, $n=sizeof($this->_trail) ; $i < $n ; ++$i) {
        $safe = $this->_trail[$i]['title'];
        $safe = ereg_replace('[^a-zA-Z0-9]+', '_', $safe);
        $safe = strtolower($safe);
        $append = $append.$safe."-";
        $test = $webdir.$append.$base;
        if(file_exists($test)) {
          $result = $badgermushroom[$base] = $webdir.$append.$base;
          return $result;
        }
      };
      // default result
      $result = $webdir.$base;
      if (!$badgermushroom[$base]) { $badgermushroom[$base] = $result; };
      if ($STICKY_CUSTOM_FILES) {
          // then we "stick" to the last look-and-feel
          return $badgermushroom[$base];
      } else {
          error_log("saying (default) ".$result);
          return $result;
      };
      return; // we never get here.
    }
    function string_only($separator="-") {
      $string="";
      for($i=0, $n=sizeof($this->_trail) ; $i < $n ; ++$i) {
        $safe = $this->_trail[$i]['title'];
        $safe = ereg_replace('[^a-zA-Z0-9]+', '_', $safe);
        $safe = strtolower($safe);
        if(strlen($string)) { $string .= $separator; }
        $string .= $safe;
      }
      return $string;
    }

    function is_part($base) {
      $append = "";
      for($i=0, $n=sizeof($this->_trail) ; $i < $n ; ++$i) {
$safe = $this->_trail[$i]['title'];
        $safe = ereg_replace('[^a-zA-Z0-9]+', '_', $safe);
        $safe = strtolower($safe);
if($append == "") {
          $append = $safe;
}
else {
          $append = $append."-".$safe;
}
if($append == $base) {
  return 1;
}
      }
      return 0;
    }
  }
 
?>
Link to comment
https://forums.phpfreaks.com/topic/18632-breadcrumb/#findComment-80274
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.