如何创建“你在这里”导航

时间:2012-09-20 06:20:52

标签: php javascript navigation

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

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

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

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

答案 2 :(得分:1)

这是应该生成“Breadcrums”的PHP代码。我假设您在所有网址结构中都有$_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;