Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Breadcrumb hell

  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Breadcrumb hell

    Hi all,
    I've downloaded short of 30 PHP Breadcrumb scripts and none of them work properly. I know enough PHP to set them up properly, it's just that they don't do what I want. Usually the last link in the list of beadcrumbs is clickable which is pointless as it will link to the same page.
    Even here in the forums I've done a search and there is very little info.

    Anyone out there got a good PHP breadcrumb script, and if you wouldn't mind sharing it, please post it up?

    A big issue is the suffix on the end of links in the location bar. I would like to hide the .php suffix.

    Thanks
    Cb
    Last edited by buildrebuild; 02-04-2007 at 03:58 PM.

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    I don't know what such a breadcrumb script looks like. On the other hand it is probably possible to modify it to get what you want.

    Perhaps you'll get better response if you show us what you have so far.

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have this but there is a problem with the way it reads my folder structure.
    I have and index page in each of my folders...
    index.php
    about(Folder) - index.php
    portfolio(Folder) - index.php
    contact(Folder) - index.php

    When I link to other files within, lets say, the porfolio folder there will be a link back to the porfolio folder+"index". I would want there just to be a link back to "portfolio".

    <?php
    $path = $_SERVER["PHP_SELF"];
    $parts = explode('/',$path);
    if (count($parts) < 2)
    {
    echo("home");
    }
    else
    {
    echo ("<a href=\"/index.php\">home</a> -> ");
    for ($i = 1; $i < count($parts); $i++)
    {
    if (!strstr($parts[$i],"."))
    {
    echo("<a href=\"");
    for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
    echo("\">".$parts[$i]."</a> ->");
    }
    else
    {
    $str = $parts[$i];
    $pos = strrpos($str,".");
    $parts[$i] = substr($str, 0, $pos);
    echo $parts[$i];
    };
    };
    };
    ?>

  • #4
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    I must be missing something. When you are viewing

    Portfolio (folder) - somepage.php

    You get generated this breadcrumb, right?

    <a href="/index.php">home</a> ->
    <a href="/portfolio/">portfolio</a> ->
    ->somepage

    Now when you click on portfolio in the bread crumb it will take you to /portfolio/ and you will get to see the page /porfolio/index.php.

    Explain what is wrong here, and how would you like it to be instead?

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, thanks for the help.
    Got this script which works a treat. Now all I need is for the first letter of each breadcrumb to be converted to a capital.


    <?php

    $path = $_SERVER["PHP_SELF"];
    $tree = split("/",$path);
    $breadcrumb = "";
    if (count($tree)==2 && $tree[1]=="index.php") { // First, check if we are on the home page
    $breadcrumb = "home";
    } else { // If not, then first put a link to the homepage
    $breadcrumb = "<a href=\"/index.php\">home</a>";
    for ($i=1; $i<count($tree); $i++) { // Now step through each level adding a link, until we reach an actual file
    if (strstr($tree[$i],".")) { // Found a file (i.e. it has a fullstop character in it)
    if ($tree[$i]!="index.php") { // If it is not the index page of the current folder, print the name
    $pagename = split("\.",$tree[$i]);
    $breadcrumb = $breadcrumb . " &gt; " . str_replace("_"," ",$pagename[0]);
    }
    } else { // Found another directory, so provide a link to the top level...
    if ($tree[$i+1]=="index.php") { // ...unless the next one down is the index page
    $breadcrumb = $breadcrumb . " &gt; " . str_replace("_"," ",$tree[$i]);
    } else {
    $breadcrumb = $breadcrumb . " &gt; <a href=\""; // Add the arrow between nodes
    for ($j=1; $j<=$i; $j++) { // Add the right link depth to the actual link
    $breadcrumb = $breadcrumb . "/" . $tree[$j];
    }
    $breadcrumb = $breadcrumb . "/\">" . $tree[$i] . "</a>";
    }
    }
    }
    }
    echo $breadcrumb; // Print the final breadcrumb trail to the page
    ?>


    Best,
    CB

  • #6
    New to the CF scene
    Join Date
    Feb 2007
    Location
    Lahore, Pakistan
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    automate only work when you have structured page system. mean if the link is page1 and dir name dir1 and it will print some thing page1 and there is no use of it.

    I think its better for you to develop your own which will suite what you want..... instead of wasting time on searching and testing...

  • #7
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    use "ucwords" ...

    http://us3.php.net/ucwords

    uppercase the first letter of a string.

    $breadcrumb=ucwords($breadcrumb;

    EDIT:
    GJay ... you beat me to it!

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    He was only 3 hours faster.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •