GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Apr-2005, 23:09
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Question

Breadcrumbs don't leave a trail


So I've tried the code I previously talked about, and it does have an issue w/ nested pages. I tried a fix from a comment, which sorta worked but not really.

If I use the original code, then the breadcrumbs look like this for every single page:
Code:
Home > Page

If I use the fix), the breadcrumbs display this on a nested page:
Code:
Home > Directory > Page
Obviously this is the physical representation on the server. But since the directory where the page is shouldn't be accessed by a visitor, a 404 error pops up when the "link" to the parent page is clicked. So how should the actual code read to get the parent page and not the parent directory?

Here's the "working" code:
PHP Code:

<?php

##############################################################################
# breadcrumb.php                  Version 1.1                                #
# Copyright 2000 Jacob Stetser    [email]jstetser@icongarden.com[/email]                    #
# Created Dec 30, 2000            Last Modified May 2, 2001                 #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright [and -left] 2000 Jacob Stetser. All Rights Reserved except as    #
# provided below.                                                            #
#                                                                            #
# breadcrumb.php may be used and modified free of charge by anyone so long   #
# as this copyright notice and the comments above remain intact. By using    #
# this code you agree to indemnify Jacob Stetser from any liability that     #
# might arise from it's use.                                                 #
#                                                                            #
# This script is released under the BSD license.                             #
# The author recognizes this script's indebtedness to evolt.org, Martin      #
# Burns, Adrian Roselli and countless other ideas of its kind. This script   #
# is therefore unencumbered free code.                                       #
##############################################################################

function breadCrumb($PATH_INFO) {
    global $page_title, $root_url;

    // Remove these comments if you like, but only distribute 
    // commented versions.
    
    // Replace all instances of _ with a space
    $PATH_INFO = str_replace("_", " ", $PATH_INFO);
    // split up the path at each slash
    $pathArray = explode("/",$PATH_INFO);
    
    // Initialize variable and add link to home page
    if(!isset($root_url)) { $root_url=""; }
    $breadCrumbHTML = '<a href="'.$root_url.'/" title="Home Page">Home</a> &gt; ';
    
    // initialize newTrail
    $newTrail = $root_url."/";
    
    // starting for loop at 1 to remove root
    for($a=1;$a<count($pathArray)-1;$a++) {
        // capitalize the first letter of each word in the section name
        $crumbDisplayName = ucwords($pathArray[$a]);
        // rebuild the navigation path
        $newTrail .= $pathArray[$a].'/';
        // build the HTML for the breadcrumb trail
        $breadCrumbHTML .= '<a href="'.$newTrail.'">'.$crumbDisplayName.'</a> &gt; ';
    }
    // Add the current page
    if(!isset($page_title)) { $page_title = "Current Page"; }
    $breadCrumbHTML .= '<strong>'.$page_title.'</strong>';
    
    // print the generated HTML
    print($breadCrumbHTML);
    
    // return success (not necessary, but maybe the 
    // user wants to test its success?
    return true;
}

?>


And here's the actual code that calls the breadcrumb.php file:
PHP Code:

<?php breadCrumb($PATH_INFO); ?>
//the original used $SCRIPT_URL instead of $PATH_INFO
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
Last edited by crystalattice : 29-Apr-2005 at 23:13. Reason: Wrong thread link
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
leave calculation andy MySQL / PHP Forum 1 26-Jul-2003 11:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:39.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.