TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   BreadCrumb Navigation (http://www.talkphp.com/general/1246-breadcrumb-navigation.html)

Tozzie 09-28-2007 05:07 AM

BreadCrumb Navigation
 
Hey again!

i was wondering if someone could help me out.
What i want to do, is use a breadcrumb style navigation script, what i want it to do it look at the url, and take certain things from it,
so if the link is this: index.php?page=tutorials&page=list&cat=photoshop
it would make "Site Name > Tutorials > Photoshop"

Thanks to anyone that can help! :D

Tanax 09-28-2007 05:32 AM

PHP Code:

$page $_GET['page'];
$cat $_GET['cat'];

echo 
$pagename ' > ' $page ' > ' $cat

Why do you have a page list after the page tutorial? It'll only confuse everything.. remove it =(

Tozzie 09-28-2007 06:01 AM

thanks :) i can use that to start off,
lol it was just a typo, the 2nd page= is act= :)

thanks alot

Wildhoney 09-28-2007 11:44 AM

I've had fun writing this function :) ! Works like a dream. Even adds in the links for you and best of all, it's all automatic. Don't forget to give TalkPHP.com a mention if you use it! Please.

PHP Code:

function get_crumbs($szSeperator ' > ')
{
    
preg_match_all('/[a-z0-9]+=+([a-z0-9]+)&?/i'$_SERVER['QUERY_STRING'], $aMatches);
    
    
$iCount 1;
    
    for(
$iIndex 0$iIndex count($aMatches[1]); $iIndex++)
    {
        
$szQuery =& $aMatches[0][$iIndex];
        
        if(
substr($szQuery, -1) == '&')
        {
            
$szQuery substr($szQuery0, -1);
        }
        
        
$aQuery = array();
        
$szItem =& $aMatches[1][$iIndex];
        
        for(
$iCycle 0$iCycle $iCount$iCycle++)
        {
            
$aQuery[] = $aMatches[0][$iCycle];
        }
        
        
$iCount++;
        
        
$szItem '<a href="?' implode('&amp;'$aQuery) . '">' ucwords(strtolower($szItem)) . '</a>';
    }
    
    return 
implode($szSeperator$aMatches[1]);
}

echo 
'<a href="page.php">TalkPHP.com</a> &gt; ' get_crumbs(); 


Salathe 09-28-2007 09:43 PM

Interesting function, Wildhoney, but sadly it won't cope (in terms of display order) if the key/value pairs come in a differently. E.g. ?act=list&cat=photoshop&page=tutorials rather than page, act, cat.

Wildhoney 09-28-2007 10:54 PM

Yep. I realise that. It's its only downfall really. However, for what he asked, it is perfect! The idea itself was flawed, not the code. As long as users don't go switching arguments then you're laughing.

Tozzie 09-29-2007 07:17 PM

Quote:

Originally Posted by Wildhoney (Post 2737)
Yep. I realise that. It's its only downfall really. However, for what he asked, it is perfect! The idea itself was flawed, not the code. As long as users don't go switching arguments then you're laughing.

:) thanks so much for that little script :D i will learn alot from it :p


All times are GMT. The time now is 02:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0