Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Breadcrumbs Script

Links for php scripts

Moderators: macek, egami, gesf

Breadcrumbs Script

Postby jpgalea » Wed Jun 29, 2005 2:11 pm

Hi

I want to include breadcrumbs in my site and was wondering if a dynamic solution using PHP would be the most appropriate way to do it.

Any suggestions or links to suitable scripts?

Thanks :)
jpgalea
New php-forum User
New php-forum User
 
Posts: 22
Joined: Fri Oct 29, 2004 11:31 pm

Postby Alexej Kubarev » Wed Jun 29, 2005 2:25 pm

What is Breadcrumbs ?
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Breadcrumbs

Postby jpgalea » Wed Jun 29, 2005 2:53 pm

Navigation aids (Name from Hansel and Gretel analogy)

ex. Home > Subpage > SubSubPage
jpgalea
New php-forum User
New php-forum User
 
Posts: 22
Joined: Fri Oct 29, 2004 11:31 pm

Postby Alexej Kubarev » Thu Jun 30, 2005 1:08 am

ahh.. multi-level navigation?
well: it would be the smartest thing to do it dynamic: plus that you can store everything in the database and give it likns by ID.. define parent_menu id in the database and you should be good to go :)
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby gesf » Thu Jun 30, 2005 3:57 pm

Ok, here you have a simple, but great example.
Done in 5 min. Damn.. it's even better than mine :(
Code: Select all
<?php

// You can use $_SERVER['HTTP_HOST'] plus $_SERVER['REQUEST_URI']
$uri = "http://www.site.com/Subpage/SubSubPage/test.php?var=value";
$uri = explode('?', $uri);

// Now we have just
// http://www.site.com/Subpage/SubSubPage/test.php
$uri = $uri[0];
$uri_parts = explode('/', $uri);

// This to make http://www.site.com
$http_host = $uri_parts[0] . '//' . $uri_parts[2];

// We've got a new $uri_parts.
// Now we have Array ( [0] => Subpage [1] => SubSubPage [2] => test.php )
$uri_parts = array_slice($uri_parts, 3);

print '<a href="' . $http_host . '">Home</a>';

$up_folder = $http_host;
foreach($uri_parts as $uri_key => $uri_value) {
   $up_folder .= '/' . $uri_value;
   print ' » <a href="' . $up_folder . '">' . ucfirst($uri_value) . '</a>';
}

?>

And... a happy end: Home » Subpage » SubSubPage » test.php

Hope it helps!
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby gesf » Thu Jun 30, 2005 4:02 pm

Oh Alexei sorry.. i forgot your theory: "Don't give whole code..."!
But this one was a great test for me... believe me :)
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Alexej Kubarev » Thu Jun 30, 2005 10:45 pm

hehe gesf : it's okey, sometimes it's useful :)
anyways: that code could be tweaked so that it would use database for generating subpages and their corresponding menys as well :)
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.