SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    How to Breadcrumb navigation with PHP?

    This morning I just started hard coding the breadcrumb navigation into each page. However I just realized what happens when I need to change a URL name or folder name. Then I have to go through and change all the breadcrumbs too. That's no good. How do I do this so that the php just magically populates the title or the URL into the breadcrumb? I have not been able to find much on google for this?

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Here is a seemingly very simple js script that creates the crumbs based on your folder structure. This is the type of stuff I'm looking for. But preferably using php instead of js. Breadcrumbs are probably pretty good for seo too. So I would prefer google to see it. http://www.javascriptkit.com/script/...eadcrumb.shtml

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Here is a php script I will try http://www.baskettcase.com/classes/breadcrumb/

    Anyone else used any other you can point me too?

  4. #4
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Here is another promising one. http://papermashup.com/how-to-displa...ite-using-php/. Can you look at this? D I have to add the main but above my doctype. Or does it not mater where?

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Same deal for this php script. http://www.whitford.id.au/webmonkey/...crumbs/php.php

    Do I have to add this line above the doctype or no?

    ?php include ( $_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php'); ?

    Bueller... Bueller... Bueller...?

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,025
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    How is the hierarchical relationship of the pages stored in the database?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are your urls build? www.example.com/page1/subpage1/subpage2/ etc or more like index.php?id=1

  8. #8
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Hey guys thanks for the reply. No database and the structure is like the following. There are many different folder names however.

    root/code/css/filename.php

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Here is another promising one. http://papermashup.com/how-to-displa...ite-using-php/. Can you look at this? D I have to add the main but above my doctype. Or does it not mater where?
    You have to add this to every php document where you wish to use the breadcrumbs. You don't need to add it above your doctype per se. I would place the breadcrumbs function in a file and include this file in your php pages where you include your other files. If you have no includes yet, just put it in the top of your php file.

    PHP Code:
    <?php

    include(/path/to/file/containing/breadcrumbs/function/file.php);

    ?>
    <doctype>
    <html>
    <head>
    </head>
    <body>
    Etc...

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Uhhhmmm... You just showed me how to include a include. Pretty sure I got that one covered. I need the function part.

  11. #11
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Apparently I'm the first in this forum to implement a beadcrumbs nav. Got to say I have not been getting much help lately. My forum post have turned into more akin to my spit balling board. A place I think out loud and solve things myself.

    Here is the best script I could find for those reading this in the future. It gives you every possible configuration you could think of. It's a bit heavy though. I'm currently looking for a smaller script. But it will do fine if Ali don't find it. http://www.baskettcase.com/classes/breadcrumb/

  12. #12
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,025
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    How many pages are there and how many "levels" deep will it go? If there's only a handfull of pages and a change of location is going to be rare then php may be overkill for generating the bread crumbs. Is there a CMS i use?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  13. #13
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Outputting a breadcrumb trail infers that there is some kind of relationship between parent pages and children (or grandchildren) pages.

    You have not described what that relationship is and how you store it.

    It could be done in a database, here is a contrived example of how 2 pages might relate to each other in the db.
    Code:
    pages_table
    =========
    
    ++++++ and example row  +++++++++
    id | 4
    parent_id | 1
    title | About us
    url | about-us
    
    ++++++ another row +++++++++
    id | 12
    parent_id | 4
    title | How to find us
    url | find-us
    That could be pulled out to give
    Code:
    <a href=/>Home</a> <a href=/about-us.php>About us</a> |  <a href=/find-us.php>How to find us</a>
    OR the relationship might be defined by files in folders.
    Code:
    /website/about-us/index.php
    /website/about-us/find-us.php
    And a similar url breadcrumb could be generated by using file reading functions as well as sstr_replace() and ucwords().

    If you explain how you establish one page knows what its parent is, and someone will try and help you make a breadcrumb from that.

    Until you do that we would be shooting in the dark, hence nobody can a helpful comment which addresses your particular situation.

  14. #14
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Duh, now I see you have started another thread .... and how you are using the file system ....

  15. #15
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    I figured it out in the other thread


Bookmarks

Posting Permissions

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