Extended Breadcrumbnavigation


/ Published in: PHP
Save to your folder(s)

customized breadcrumbnavigation for PHPWCMS.
Gives more control over styling and display.
{MYBREADCRUMB:n}


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function mybreadcrumb ($start_id, &$struct_array, $end_id, $spacer=' &gt; ') {
  4. //builds the breadcrumb menu based on given values
  5. //$link_to = the page on which the breadcrum part links
  6. //$root_name = name of the breadcrumb part if empty/false/0 $start_id
  7. //$spacer = how should breadcrumb parts be divided
  8.  
  9. $start_id = intval($start_id);
  10. $end_id = intval($end_id);
  11. $act_id = $start_id; //store actual ID for later comparing
  12. $breadcrumb = '';
  13.  
  14. while ($start_id) { //get the breadcrumb path starting with given start_id
  15. if($end_id && $start_id == $end_id ) break;
  16. $data[$start_id] = $struct_array[$start_id]["acat_name"];
  17. $start_id = $struct_array[$start_id]["acat_struct"];
  18.  
  19. }
  20. $data[$start_id] = $struct_array[$start_id]["acat_name"];
  21. $crumbs_part = array_reverse($data, 1);
  22. //print_r($crumbs_part);
  23. if(is_array($crumbs_part)) {
  24. $i=1;
  25. foreach($crumbs_part as $key => $value) {
  26. $alias = '';
  27. $active = ($i == count($crumbs_part)-1)? "pre_active" : "";
  28. $active .= ($i == count($crumbs_part))? "active" : "";
  29. if($struct_array[$key]["acat_hidden"] != 1) { // check if the structure should be unvisible when active
  30. if ($act_id != end_id) {
  31. if($breadcrumb) $breadcrumb .= $spacer;
  32. if(!$struct_array[$key]["acat_redirect"]) {
  33. $breadcrumb .= '<a class="breadcrumb_level_'.$i.' '.$active.'" href="index.php?';
  34. $alias = $struct_array[$key]["acat_alias"];
  35. $breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key.',0,0,1,0,0';
  36. $breadcrumb .= '">';
  37. } else {
  38. $redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
  39. $breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
  40. }
  41. $breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
  42. } else {
  43. if($breadcrumb) $breadcrumb .= $spacer;
  44. $breadcrumb .= html_specialchars($crumbs_part[$key]);
  45. }
  46. $i++;
  47. }
  48. }
  49. }
  50. return $breadcrumb;
  51. }
  52.  
  53.  
  54.  
  55. //breadcrumb replacement
  56. if(strpos($content["all"],'{MYBREADCRUMB') !== false) {
  57. $content["all"] = str_replace('{MYBREADCRUMB}', '{MYBREADCRUMB:0}', $content["all"]);
  58. $replace = '@mybreadcrumb($GLOBALS["content"]["cat_id"], $GLOBALS["content"]["struct"], $1, $template_default["breadcrumb_spacer"]);';
  59. $content["all"] = preg_replace('/\{MYBREADCRUMB:(\d+)\}/e', $replace, $content["all"]);
  60. }
  61. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.