I think this script is of big interest to any noob around here :) including me :)
What I want to create is a little code that I can use in any file and will generate a breadcrumb like this:
If the file is called "website.com/templates/index.php" the breadcrumb should show:
Website.com > Templates
^^ link ^^plain text
If the file is called "website.com/templates/template_some_name.php" the breadcrumb should show:
Website.com > Templates > Template Some Name
^^ link ^^link ^^plain text
I started with the code from Dominic Barnes, incorporated the feedback from cWoDeR and I still had problems with the breadcrumbs at the third level when I used a sub-directory. So I rewrote it and have included the code below.
Note that I have set up my web site structure such that pages to be subordinate to (linked from) a page at the root level are set up as follows:
Create a folder with the EXACT same name as the file (including capitalization), minus the suffix, as a folder at the root level
place all subordinate files/pages into this folder
(eg, if want sobordinate pages for Customers.php:
create a folder called Customers at the same level as Customers.php
add an index.php file into the Customers folder which redirects to the calling page for the folder (see below for code)
This structure will work for multiple levels of subfolders.
Just make sure you follow the file structure described above AND insert an index.php file with the code shown in each subfolder.
The code in the index.php page in each subfolder looks like:
If you use the root directory of the server as your web root (ie /var/www/html) then set $root_dir="": (do NOT leave the trailing "/" in). If you use a subdirectory for your web site (ie /var/www/html/web_root then set $root_dir = "web_root/"; (replace web_root with the actual name of your web directory)(make sure to include the trailing /)
at any rate, here is my (derivative) code:
This is the code that i personally use in my sites. Works outside of the box.
The css:
Feel free to play around with the css padding and margins until you get it right for your own site.
hey dominic your answer was nice but if your have a site like http://localhost/project/index.php the 'project' link gets repeated since it's part of $base and also appears in the $path array. So I tweaked and removed the first item in the $path array.
I dont know if that is the most elegant way, but it now works for me.
I add that code before this one on line 13 or something
A better one using
explode()
function is as follows...Don't forget to replace your URL variable in the hyperlink
href
.Also made a little script using RDFa (you can also use microdata or other formats) Check it out on google This script also keeps in mind your site structure.
use
parse_url
and then output the result in a loop:(pseudocode)