【问题标题】:How to create "you are here" navigation [closed]如何创建“你在这里”导航[关闭]
【发布时间】:2012-09-20 06:20:51
【问题描述】:

我需要在我的网站上添加“你在这里”导航链接。例如:

Home->Automobiles->cars

我可以假设的唯一方法是对网页中的链接进行硬编码。如果需要,我有很多文件。有没有简单的方法或替代方法来克服这个问题?感谢您的建议。谢谢。

注意:我在我的网站上使用 mod Rewrite 如本例所示:

RewriteRule ^Automobiles/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /Automobiles/info.php?make=$1&model=$2&ad_id=$3&name=$4 [L]

链接是这样的:

http://www.abc.com/Automobiles/Nissan/Sunny/1/Car_for_sale.html

我需要像这样的导航:

Home->Automobiles->Car_for_sale

【问题讨论】:

  • 它们被称为面包屑,如果他们不知道您网站的结构和编程,没有人可以告诉您如何做到这一点。
  • 你的页面是否被动态加载了?
  • @Matei Mihai 是的朋友,它是动态加载的
  • @vinu 您能否提供一个有关您的 URL 结构、重写规则等的示例,这对找到一个好的解决方案很有帮助?你的网站上线了吗?

标签: php javascript navigation


【解决方案1】:

这里有很好的教程:

Display breadcrumbs on your site using PHP

【讨论】:

【解决方案2】:

这是应该生成“面包屑”的 PHP 代码。我假设您的所有 URL 结构中都有 $_REQUEST['name'] 的值。

// your Breadcrums!
$b = '';

// you need to have this array in order to link each 'alias' to its own 'ID'
$cat['auto'] = 1;
$cat['realestate'] = 2;
// etc.

// home page is always available, right?
// Output: Home
$b .= '<a href="/">Home</a>';

// if we have main category already passed on the URI
// current category
$c_cat = strtok($_SERVER['REQUEST_URI'], '/');

if (!empty($c_cat) AND !empty($cat[$c_cat]))
    // Output: Home -> Auto
    $b .= ' -> <a href="/?id=' . $cat[$c_cat] . '">' . ucfirst($c_cat) . '</a>';

// if we have 'ad name'
if (!empty($_REQUEST['name'])
    // Output: Home -> Auto -> Mustang GT500
    // should not be linked, huh?
    $b .= ' -> ' . $_REQUEST['name'];

// end
echo $b;

【讨论】:

  • 现在我明白了。太好了,这对我有用,非常感谢。
  • 不客气,很高兴听到这有帮助! :)
【解决方案3】:

我认为您正在寻找“面包屑”。你有几个例子: Herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2015-05-18
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-14
    相关资源
    最近更新 更多