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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 32

Thread: breadcrumb help

  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation breadcrumb help

    After trying alot of tutorials on breadcrumbs I have found this one the best so far:
    http://gr0w.com/articles/code/php_br...links_creator/

    I have got it to work on my home page but when I use it on another page it doesnt work

    On my homepage in dreamweaver I have put this php code on my footer because this is where I want my breadcrumbs:
    PHP Code:
    <?php $pagetitle="Home"; include("http://www.newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php"); ?>
    This is inside the included file breadcrumb.php:
    PHP Code:
    <?php
    $ul_id
    ='crumbs';
    $bc=explode("/",$_SERVER["PHP_SELF"]);
    echo 
    '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>';
    while(list(
    $key,$val)=each($bc)){
     
    $dir='';
     if(
    $key 1){
      
    $n=1;
      while(
    $n $key){
       
    $dir.='/'.$bc[$n];
       
    $val=$bc[$n];
       
    $n++;
      }
      if(
    $key count($bc)-1) echo '<li><a href="'.$dir.'">'.$val.'</a></li>';
     }
    }
    echo 
    '<li>'.$pagetitle.'</li>';
    echo 
    '</ul>';
    ?>
    When I view the page source of my homepage in firefox this is the code I see:
    PHP Code:
    <ul id="crumbs"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li><li></li></ul
    I am not sure why there are so many </li>?

    I have put the code below on my contact page:
    PHP Code:
    <?php $pagetitle="Contact"; include("http://www.newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php"); ?>
    When I view the contact page it still says Home and not Home > Contact

    I tried adding a second $pagetitle2:
    PHP Code:
    <?php $pagetitle="Home"$pagetitle2="Contact";include("http://www.newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php"); ?>
    and in the breadcrumb file I have added this:
    PHP Code:
    echo '<li>'.$pagetitle.'</li>';
    echo 
    '<li>'.$pagetitle2.'</li>'
    Nothing seems to work. I thought this was supposed to be easy lol

    Please can someone help!?

  • #2
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone?

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    By including the file using a http wrapper - http://www.newmedia.lincoln.ac.uk/ the include() function is actually making a http request back to your web server for the file. The file is being parsed by php and only any output from that file is being included. This also means that any variables you set outside of the file don't exist in the parsed code, which is why your $pagetitle variable value does not show up.

    You need to include your file locally through a file system reference, not a http request.

    There is another current thread with the same problem, see posts #16 and #17 in this thread - Variable/Array not taking in another folder
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    You need to include your file locally through a file system reference, not a http request.

    There is another current thread with the same problem, see posts #16 and #17 in this thread - Variable/Array not taking in another folder
    Ok I read the posts 16 and 17 and I have noted you saying I need to specify a file system path.

    Where and how exactly can I apply this in the code above? I have entered in the URL of my home page on this line:
    echo '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>';

    How and where do I specify a file system path?

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    file system path is one which looks like
    PHP Code:
    include("dir/to/incs/inc.me.inc");
    //not
    include("http://www.google.com");
    //or 
    include("www.google.com"); 

  • #6
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    ok so I changed:
    PHP Code:
     <?php $pagetitle="Home"; include("http://www.newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php"); ?>
    to:
    PHP Code:
     <?php $pagetitle="Home"; include("newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php"); ?>
    The browser is saying this:
    Warning: main(newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php): failed to open stream: No such file or directory in /home/webmedia/public_html/jecgardner/index.php on line 252

    Warning: main(): Failed opening 'newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/webmedia/public_html/jecgardner/index.php on line 252
    In the breadcrumb.php file there is this line:
    PHP Code:
    echo '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>'
    Should I add copy and paste this line for my other pages like this:

    PHP Code:
    echo '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Contact</a></li>'
    ??

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    include '/home/webmedia/public_html/jecgardner/breadcrumb.php'

  • #8
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still not working.. The browser doesn't give me an error no more but when I view my index page there is now no link on the footer?

    This is where the breadcrumb is:
    http://www.newmedia.lincoln.ac.uk/je...breadcrumb.php

    I have added the following lines to the breadcrumb.php file:
    PHP Code:
    echo '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/contact.php">Contact</a></li>';
    echo 
    '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/year2.php">Year 2</a></li>';
    echo 
    '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/year3.php">Year 3</a></li>'
    When you view the contact page on the footer it lists all the links (year2 and year3) but when you view the home page it doesn't even display the Home link??

    This is where I have put the include:
    Code:
    <div id="footer_bl"></div>
    Last edited by youandI; 09-11-2007 at 01:30 PM.

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You're still putting the file path wrong.

    You're putting:

    newmedia.lincoln.ac.uk/jecgardner/breadcrumb.php

    It's not that, it's:

    /home/webmedia/public_html/jecgardner/breadcrumb.php

  • #10
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did what you told me to do the first time:
    PHP Code:
    <?php $pagetitle="Home"'/home/webmedia/public_html/jecgardner/breadcrumb.php'?>
    But in the breadcrumb.php file I have:
    PHP Code:
    echo '<ul id="'.$ul_id.'"><li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>'

  • #11
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I have changed this code in breadcrumb.php to the following:
    PHP Code:
    echo '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/contact.php">Contact</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/year2.php">Year 2</a></li>'
    When you view my homepage there is no Home link in the footer? But when you view the contact page it lists all of these in the footer:
    # Home
    # Contact
    # Year 2
    # Contact

    On the contact page it should just be Home > Contact

    Why is it showing links to all the other pages in the footer and why isnt there any link on my home page?

  • #12
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    It's not that, it's:

    /home/webmedia/public_html/jecgardner/breadcrumb.php
    This may not be wrong, it is bad.

    If your website root is /home/webmedia/public_html/jecgardner/, you just need to do:

    PHP Code:
    include 'breadcrumb.php'
    Never use absolute paths unless it is completely necessary (rarely).

  • #13
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Ok I am using this on my homepage:
    PHP Code:
    <?php $pagetitle="Home"; include 'breadcrumb.php'?>
    on my
    and I am using this on my contact page:
    PHP Code:
    <?php $pagetitle="Contact";  include '/home/webmedia/public_html/jecgardner/breadcrumb.php'?>
    Both seem to be ok but each page now lists all the links in the footer that I have added into the breadcrumb.php file.

    On my home page I just want it to display: Home
    On the contact page footer I want it to look like this: Home > Contact

    Why does the home page and contact page both show all the links on the footer??:
    • Home
    • Contact
    • Year 2


    This is how the breadcrumb.phps looks like:
    PHP Code:
    <?
    $ul_id
    ='crumbs';
    $bc=explode("/",$_SERVER["PHP_SELF"]);
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/contact.php">Contact</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/year2.php">Year 2</a></li>';
    while(list(
    $key,$val)=each($bc)){
     
    $dir='';
     if(
    $key 1){
      
    $n=1;
      while(
    $n $key){
       
    $dir.='/'.$bc[$n];
       
    $val=$bc[$n];
       
    $n++;
      }
      if(
    $key count($bc)-1) echo '<li><a href="'.$dir.'">'.$val.'</a></li>';
     }
    }
    echo 
    '<li>'.$pagetitle.'</li>';
    echo 
    '</ul>';
    ?>

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Because you're echo'ing them at the top
    PHP Code:
    echo '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/">Home</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/contact.php">Contact</a></li>';
    echo 
    '<li><a href="http://www.newmedia.lincoln.ac.uk/jecgardner/year2.php">Year 2</a></li>'

  • #15
    New Coder
    Join Date
    May 2007
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok its nearly working.. I would like to ask a few more questions:

    The footer on my homepage repeats Home twice (Home > Home) to make it say one Home I deleted $pagetitle="Home" from:
    PHP Code:
    <?php $pagetitle="Home"; include '/home/webmedia/public_html/jecgardner/breadcrumb.php'?>
    I dont know if this is cheating or acceptable to delete $pagetitle="Home" so it says Home once. I have left the pagetitle in place so you can see what I mean CLICK HERE and scroll to the footer to see what I mean!

    The contact page, year 2 and year 3 pages breadcrumb seem to be working fine

    However I have another problem when I try to add the breadcrumb to my comments page. This is because my comments page (journal.php) is inside a folder and not on the root directory.

    This is the code I added to the comments footer:
    PHP Code:
    <?php $pagetitle="Comments"; include '/home/webmedia/public_html/jecgardner[U]/entry/[/U]breadcrumb.php'?>
    This is what displays on the comments page:
    Home > jecgardner
    Comments

    Why is it showing jecgardner? I have tried linking the breadcrumb like I have on all the other pages and I have also added the same breadcrumb file into the entry folder which is shown above. Any ideas how to fix this please?

    I have one more question! Which is about the arrow (>) I have added in the breadcrumb.php file:
    PHP Code:
    echo ' > '.$pagetitle.' '
    I was wondering how to not have the arrow appear on the home page? It looks ok on all the other pages Home > Contact.. But Home > wouldnt make sense? Is there a way around this?

    Thanks for all the help!


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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