Jump to content

Create a Breadcrumbs Trail For a Website


BorysSokolov
Go to solution Solved by requinix,

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.

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.