Jump to content

Create a Breadcrumbs Trail For a Website


BorysSokolov

Recommended Posts

I've been trying to make a breadcrumbs navigation for a simple website which uses GET variables to determine what content to display, but it's proving a little bit more tricky than I thought. I've typed up a simple code already, but I'm looking to improve it and make it more dynamic:

<?php
$url_vars = array();//the correct GET variables
$url_vars[0] = 'girls';//www.mywebsite.com/girls
$url_vars[1] = 'boys';//www.mywebsite.com/boys

$url_exp = explode('/', $_SERVER['REQUEST_URI']);
$url_path = array();

foreach($url_exp as $shard){
	foreach($url_vars as $var){
		if($var == $shard){
			$url_path[] = $shard;
			break;
		}
	}
}


require 'pre_breadcrumbs.html';//displays home crumb
foreach($url_path as $crumb){
	echo ' -> ';
	$full_crumb = ucfirst($crumb);

	require 'breadcrumbs.html';//creates all the crumbs
}
?>

Any ideas?

 

Thanks.

It depends on how your site works. Your method for building $url_path is odd* but for all I know that's intentional.

 

Though I will say you should have links for the crumbs if at all possible/sensible.

 

* Normally you get breadcrumbs by looking at the structure associated with whatever page is being served. This may or may not be reflected in the URL structure: phpfreaks here only shows "topic/277963-*" in the URL but there's actually a hierarchy of Forum > PHP Coding > PHP Coding Help > This thread.

It depends on how your site works. Your method for building $url_path is odd* but for all I know that's intentional.

 

Though I will say you should have links for the crumbs if at all possible/sensible.

 

* Normally you get breadcrumbs by looking at the structure associated with whatever page is being served. This may or may not be reflected in the URL structure: phpfreaks here only shows "topic/277963-*" in the URL but there's actually a hierarchy of Forum > PHP Coding > PHP Coding Help > This thread.

 

How could I create a hierarchy like that?

Depends on how your site works. Really, really depends. So how does it?

 

I'm not exactly sure what to explain. Like I said, my site uses GET variables to determine what content to display.

if(!empty($g)){
		if($g=='boys'){
			require 'men_hero.html';
		}else if($g=='girls'){
			require 'women_hero.html';
		}else{
			header('Location: http://localhost/breadcrumbs/');
		}
}

In other files there are other variables, and all of them are reflected in the URL. I've used mod_rewrite, however, to change ~ www.mysite.com?g=girls to www.mysite.com/girls

 

Prior to this, the breadcrumbs code runs.

 

I don't think I understand what exactly you mean by a hierarchy? A hierarchy of variables?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.