dongxiong2000 2014-07-16 11:16
浏览 91
已采纳

动态面包屑URL

I have found this code online and it pretty much does what I would like it todo but there are just a few issues.

When I click on the home tab it adds https in front of the domain and it says this website is not available but if I remove the s it works.

also on the websites there are titles like home > aaa-bbb-ccc > aaa-bbb > aaa I will supply the old breadcrumb code we have and i'm wondering if we specify the url for the breadcrumbs.

Also when I view the website in the browser in the middle of the breadcrumb this appears Home > $title > index

Old Breadcrumbs:

    <?php
/*
Copyright Justin Whitford 2006.
  http://www.whitford.id.au/
Perpetual, non-exclusive license to use this code is granted
on the condition that this notice is left in tact.
*/
function breadcrumbs(){
  $bread = explode('/', $_SERVER['PHP_SELF']);
  $url = '/';
  $returnString = "<span class='bc0'><a href='$url'>Home</a>";
  for($i=1;$i<count($bread)-1;$i++){
    $url.=$bread[$i].'/';
    $returnString .= " ></span> <span class='bc$i'><a href='$url'>"
      .prettify($bread[$i])."</a>";
  }
  echo $returnString.'</span>';
}
function prettify($dirName){

$directoryName['aaa-bbb-ccc']='Locate Us';
$directoryName['aaa-bbb']='Contact';

  $directoryName['breadcrumbs']='Foe';
  if($directoryName[$dirName]!=''){
    $dirName=$directoryName[$dirName];
  }else{
    $dirName = str_replace('_', ' ', $dirName);
    $dirName = str_replace('%20', ' ', $dirName);
    $dirName = ucwords(strtolower($dirName));
  }
  return $dirName;
}

This is my new code:

<?php
function breadcrumbs($separator = ' > ', $home = 'Home') {

$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
$base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
$breadcrumbs = array("<a href=\"$base_url\">$home</a>");

$last = end(array_keys($path));

foreach ($path AS $x => $crumb) {
$title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
if ($x != $last){
$breadcrumbs[] = '<a href="$base_url$crumb">$title</a>';
}else{
$breadcrumbs[] = $title;
}
}

return implode($separator, $breadcrumbs);
}


echo breadcrumbs();
?>

Thanks.

  • 写回答

1条回答 默认 最新

  • doubiaode0460 2014-07-16 11:34
    关注

    try to use

    $base_url = "http://". $_SERVER['HTTP_HOST'] . "/"`
    

    and remove that checking. It is because at first check $_SERVER['HTTPS'] ? 'https' : 'http') may return https. Use that only if you have a secured domain. That is an 'https://' domain

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”