Jump to content


Photo

Breadcrumb ...


  • Please log in to reply
5 replies to this topic

#1 jimbobsquarepants

jimbobsquarepants
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 25 August 2006 - 10:01 AM

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

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 August 2006 - 10:11 AM

Anything's possible  ;)

It sounds as though you could stick the if statement in there without much trouble.  Obviously it depends on how you're generating the breadcrumb in the first place, but yeah, should be easy enough.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 jimbobsquarepants

jimbobsquarepants
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 25 August 2006 - 10:18 AM

Rich thanks for that ...

what kinda info do you need to know to help me with the code?

Cheers

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 August 2006 - 10:20 AM

Ideally the code you're using to generate the breadcrumb.  Then we can point you in the right direction.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 jimbobsquarepants

jimbobsquarepants
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 25 August 2006 - 10:23 AM

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 © 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;
    }
  }
 
?>

#6 jimbobsquarepants

jimbobsquarepants
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 25 August 2006 - 10:24 AM

and then in the header i

echo $breadcrumb->trail(' &raquo; ');

cheers




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users