2

I need to add "you are here" navigation links to my website. For example:

Home->Automobiles->cars

The only way I can assume is hard coding links in the webpage. I have lots of files if I need to do so. Are there any simple ways or alternatives to overcome this? Your advice is appreciated. Thanks.

NOTE: I am using mod Rewrite in my website as in this example:

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

The link is something like this:

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

I need the navigation to be like:

Home->Automobiles->Car_for_sale
Jack Bonneman
  • 1,821
  • 18
  • 24
vinu
  • 658
  • 10
  • 20
  • 4
    They are called breadcrumbs, and noone can tell you how to do that if they don't know your website's structure and programming. – Mihai Iorga Sep 20 '12 at 06:23
  • Check this out http://stackoverflow.com/questions/12443923/build-an-html-title-tag-dynamically-with-javascript/12444584#12444584 – elclanrs Sep 20 '12 at 06:23
  • Is your pages dinamycally loaded ? – Mihai Matei Sep 20 '12 at 06:24
  • @Matei Mihai Yes friend,it is dynamically loaded – vinu Sep 20 '12 at 06:26
  • @vinu can you provide an example of your URL structure, your rewrite rules, etc. that would helps so much to find a good solution? Does your website online? – Mahdi Sep 20 '12 at 06:46
  • @Mahdi I have edited my question. Site is in offline for development.Thanks – vinu Sep 20 '12 at 06:54
  • @vinu what is the difference between 'Home' and 'Home->Auto'? Is it a valid like: 'abc.com/auto/'? you have other things like 'abc.com/anything/' or not? if yes, hard-coded or via mod_rewrite? – Mahdi Sep 20 '12 at 07:01
  • @Mahdi My site is a classifieds website.So i have automobiles,Real estate classifieds.links to these two are like http://www.abc.com/Automobiles/index.php and http://www.abc.com/Realestates/index.php if i click on a classified it goes as http://www.abc.com/Automobiles/info.php?id=1 but i call rewrite URL as above in my question – vinu Sep 20 '12 at 07:31

3 Answers3

2

Excellent tutorial here:

Display breadcrumbs on your site using PHP

Frankline
  • 40,277
  • 8
  • 44
  • 75
  • Thanks This works Perfectly okay. Got another problem,my page URLs are rewritten from mod-rewrite.At that point its not working properly.:( – vinu Sep 20 '12 at 06:36
  • Might this help: [Create a URL from a string of text with PHP and mod_rewrite](http://papermashup.com/create-a-url-from-a-string-of-text-with-php/) – Frankline Sep 20 '12 at 06:50
1

I think you are looking for "Breadcrums". You have several examples in: Here and here.

Community
  • 1
  • 1
mantoviejo
  • 168
  • 1
  • 12
1

Here is the PHP code that should generate your "Breadcrums". I assumed that you have the value of $_REQUEST['name'] in all of your URL Structure.

// 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;
Mahdi
  • 9,247
  • 9
  • 53
  • 74